当前位置: 首页>>代码示例>>C#>>正文


C# Repository.Add方法代码示例

本文整理汇总了C#中Repository.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.Add方法的具体用法?C# Repository.Add怎么用?C# Repository.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Repository的用法示例。


在下文中一共展示了Repository.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            var soapShopDb = new SoapShopDb();
            var component = new Repository(soapShopDb);

            // Adding some entity
            component.Add(new Customer { CustomerName = "Nata", CustomerPhone = "679011198" });
            component.Save();
            component.Add(new SoapProduct { Tittle = "Eucalyptus", Mass = 100, Price = 25.2M });
            component.Save();

            // Delating some entity
            var comp = soapShopDb.Set<Customer>().FirstOrDefault(i => i.CustomerName == "Nata");
            component.Delete(comp);
            component.Save();

            // Reading some entity
            var list = component.Get<Customer>();
            foreach (var item in list)
            {
                Console.WriteLine(item.Id + " " + item.CustomerName + " " + item.CustomerPhone + "\n");
            }

            // Find one
            var comp2 = component.Get<Customer>(3);
            Console.WriteLine(comp2.CustomerName);
        }
开发者ID:Gorova,项目名称:task3,代码行数:27,代码来源:Program.cs

示例2: Get_EmptyRepository_ReturnsCorrectResult

 public void Get_EmptyRepository_ReturnsCorrectResult()
 {
     var course = new Course("Java basics");
     var course2= new Course("C Sharp advanced");
     var repository = new Repository<Course>();
     repository.Add(course);
     repository.Add(course2);
     var result = repository.Get(1);
     var result2 = repository.Get(2);
     Assert.AreEqual(course, result);
     Assert.AreEqual(course2, result2);
 }
开发者ID:EBojilova,项目名称:CSharpHQC,代码行数:12,代码来源:RepositoryTests.cs

示例3: TestGetWhitManyItems

 public void TestGetWhitManyItems()
 {
     int input = It.IsAny<int>();
     int input2 = It.IsAny<int>();
     int input3 = It.IsAny<int>();
     Repository<int> repository = new Repository<int>();
     repository.Add(input);
     repository.Add(input2);
     repository.Add(input3);
     var actualResult = repository.Get(2);
     Assert.AreEqual(input2, actualResult);
 }
开发者ID:ikolev94,项目名称:Exercises,代码行数:12,代码来源:GetTests.cs

示例4: Get_WithManyEntries_ShouldReturnCorrectEntry

        public void Get_WithManyEntries_ShouldReturnCorrectEntry()
        {
            var repository = new Repository<User>();
            var user = new User("Ivan Ivanov", "123456", Role.Student);
            var user2 = new User("Ivan Ivanov2", "123456", Role.Student);
            var user3 = new User("Ivan Ivanov3", "123456", Role.Student);
            repository.Add(user);
            repository.Add(user2);
            repository.Add(user3);
            var result = repository.Get(2);

            Assert.AreEqual(user2, result);
        }
开发者ID:EBojilova,项目名称:CSharpHQC,代码行数:13,代码来源:RepositoryTests.cs

示例5: TestGet_InitializeRepoOfStrings_ShouldReturnElement

        public void TestGet_InitializeRepoOfStrings_ShouldReturnElement()
        {
            // Arrange
            var namesRepo = new Repository<string>();
            namesRepo.Add("Stoyan");
            namesRepo.Add("Valio");
            namesRepo.Add("Pecata");

            // Act
            var name = namesRepo.Get(1);

            // Assert
            Assert.AreEqual("Stoyan", name, "Returned name should be Stoyan");
        }
开发者ID:eslavov11,项目名称:SoftUni-Homework,代码行数:14,代码来源:RepositoryTests.cs

示例6: AddGroup

        public MessageResultDto AddGroup(string name)
        {
            Group group = null;
            var result = new MessageResultDto();

            using (ISession session = _sessionFactory.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                IRepository<Group> groupRepository = new Repository<Group>(session);
                var existingGroup = groupRepository.FindOne(new Tuple<Expression<Func<Group, object>>, string>(x => x.Name, name));

                if (null == existingGroup)
                {
                    group = new Group { Name = name };
                    groupRepository.Add(group);
                    transaction.Commit();
                    result.SuccessMessage("Group added successfully", group.Id);
                }
                else
                {
                    result.ErrorMessage("Group with same name already exisits");
                }
            }
            return result;
        }
开发者ID:avijassra,项目名称:MyNotes,代码行数:25,代码来源:GroupStorageProxy.cs

示例7: add

        public static Result add(School school)
        {
            using (SGContext db = new SGContext())
            {
                try
                {
                    var repo = new Repository<School>(db);
                    var sch = repo.Find(d => d.Ad == school.Ad && d.IsDeleted == false);
                    var schmeb = repo.Find(d => d.MebKodu == school.MebKodu && d.IsDeleted == false);

                    if (sch.Count() > 0)
                    {
                        result = new Result(SystemRess.Messages.hata_ayniOkulSistemdeMevcut.ToString(), SystemRess.Messages.hatali_durum.ToString());
                        return result;
                    }
                    else if (schmeb.Count() > 0)
                    {
                        result = new Result(SystemRess.Messages.hata_ayniMebKoduSistemdeMevcut.ToString(), SystemRess.Messages.hatali_durum.ToString());
                        return result;
                    }
                    repo.Add(school);
                    result = new Result(SystemRess.Messages.basarili_kayit.ToString(), SystemRess.Messages.basarili_durum.ToString());
                    return result;
                }
                catch (Exception)
                {
                    result = new Result(SystemRess.Messages.hatali_kayit.ToString(), SystemRess.Messages.hatali_durum.ToString());
                    return result;
                }
            }
        }
开发者ID:sakurahoshi,项目名称:appointment,代码行数:31,代码来源:SchoolManager.cs

示例8: Create

 public ActionResult Create(Fund fund)
 {
     try
     {
         if (ModelState.IsValid)
         {
             //fundRepository.InsertFund(fund);
             NHibernateHelper helper = new NHibernateHelper("thangma");
             // Notice the unit of work we are using is to commit
             //    one truck's data at a time.
             UnitOfWork unitOfWork = new UnitOfWork(helper.SessionFactory);
             Repository<Fund> repository = new Repository<Fund>(unitOfWork.Session);
             //Truck truck = CreateFund();
             repository.Add(fund);
             unitOfWork.Commit();
             return RedirectToAction("Index");
         }
     }
     catch (DataException)
     {
         //Log the error (add a variable name after DataException)
         ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
     }
     return View(fund);
 }
开发者ID:thangma,项目名称:thangmaapp,代码行数:25,代码来源:FundController.cs

示例9: Handle

        public Unit Handle(Repository repository)
        {
            var product = new Product(Name, Price);
              repository.Add(product);

              return Unit.Default;
        }
开发者ID:njmube,项目名称:public,代码行数:7,代码来源:ProductCreatedEvent.cs

示例10: AddUser

        public MessageResultDto AddUser(string firstname, string lastname, string nickname, string username, string password, Guid groupId)
        {
            var result = new MessageResultDto();

            using (ISession session = _sessionFactory.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                IRepository<Group> groupRepository = new Repository<Group>(session);
                var group = groupRepository.FindOne(x => x.Id == groupId);

                IRepository<User> userRepository = new Repository<User>(session);
                var existingUser = userRepository.FindOne(x => x.Username == username);

                if (null == existingUser)
                {
                    userRepository.Add(new User
                    {
                        FirstName = firstname,
                        LastName = lastname,
                        Nickname = nickname,
                        Username = username,
                        Password = password,
                        Group = group
                    });

                    transaction.Commit();
                }
                else
                {
                    result.ErrorMessage("User with same username already exists");
                }
            }
            return result;
        }
开发者ID:SadiqAhmed,项目名称:MyNotes,代码行数:34,代码来源:UserStorageProxy.cs

示例11: Insert

        public void Insert()
        {
            using (var context = new MainContext())
            {
                var myRepo = new Repository<Address>(context);
                TotalAdresssBeforeTestRuns = myRepo.GetAll().Count();

                //Have to provide a valid name and e-mail address
                MyNewAddress = new Address
                {
                    AddressLine1 = "Barão de Mesquita Street",
                    AddressLine2 = "Tijuca",
                    Country = MyCountryTest,
                    State = "RJ",
                    Zip = "20540-156"
                };

                myRepo.Add(MyNewAddress);
                myRepo.Save();

                TotalOfClientsAfterTheTestRuns = myRepo.GetAll().Count();

                //Assert that the number of clients increase by 1
                Assert.AreEqual(TotalAdresssBeforeTestRuns + 1, TotalOfClientsAfterTheTestRuns);
            }
        }
开发者ID:rafaelfernandesnet,项目名称:HotelClub,代码行数:26,代码来源:AddressRepositoryCanInsert.cs

示例12: NothingShouldGoBang

        public void NothingShouldGoBang()
        {
            var factStore = new MemoryFactStore();
            var aggregateRebuilder = new AggregateRebuilder(factStore);
            var snapshot = new QueryModel<Student>(aggregateRebuilder);
            var eventBroker = Substitute.For<IDomainEventBroker>();

            Guid studentId;

            using (var unitOfWork = new UnitOfWork(factStore, eventBroker, new SystemClock()))
            {
                var repository = new Repository<Student>(snapshot, unitOfWork);

                var student = Student.Create("Fred", "Flintstone");
                studentId = student.Id;
                repository.Add(student);

                unitOfWork.Complete();
            }

            using (var unitOfWork = new UnitOfWork(factStore, eventBroker, new SystemClock()))
            {
                var repository = new Repository<Student>(snapshot, unitOfWork);
                var student = repository.GetById(studentId);

                student.FirstName.ShouldBe("Fred");
                student.LastName.ShouldBe("Flintstone");
            }
        }
开发者ID:uglybugger,项目名称:Sourcerer,代码行数:29,代码来源:WhenCreatingThenRehydratingAnAggregateRoot.cs

示例13: AddNewsWhenNewsIsAddedToDbShouldReturnNews

        public void AddNewsWhenNewsIsAddedToDbShouldReturnNews()
        {
            //Arange -> prepare the objects
            var repo = new Repository<Models.News>(new NewsContext());
            var news = new Models.News()
            {
                Id = 1,
                Title = "title 1",
                Content = "content 1",
                PublishedData = DateTime.Now
            };

            //Act -> perform some logic
            repo.Add(news);
            repo.SaveChanges();

            //Assert -> validate the results
            var newsFromDb = repo.GetById(news.Id);

            Assert.IsNotNull(newsFromDb);
            Assert.AreEqual(news.Title, newsFromDb.Title);
            Assert.AreEqual(news.Content, newsFromDb.Content);
            Assert.AreEqual(news.PublishedData, newsFromDb.PublishedData);
            Assert.IsTrue(newsFromDb.Id != 0);
        }
开发者ID:Aleksandyr,项目名称:Software-University,代码行数:25,代码来源:RepositoriesTest.cs

示例14: Initializer

        public virtual void Initializer()
        {
            //Add a client to be removed by our test.

            //Instantiate a new context.
            using (var context = new MainContext())
            {
                //Create a repository based on the context.
                var myRepo = new Repository<Address>(context);

                //Have to provide valid info.
                MyNewAddress = new Address
                {
                    AddressLine1 = "Barão de Mesquita Street",
                    AddressLine2 = "Tijuca",
                    Country = MyCountryTest,
                    State = "RJ",
                    Zip = "20540-156"
                };

                myRepo.Add(MyNewAddress);

                myRepo.Save();
            }
        }
开发者ID:rafaelfernandesnet,项目名称:HotelClub,代码行数:25,代码来源:AdressRepositoryBase.cs

示例15: CreateUser

        public static Result CreateUser(User newUser)
        {
            using (SGContext db = new SGContext())
            {
                try
                {
                    var userRepository = new Repository<User>(db);
                    var user = userRepository.Find(d => d.TCKimlik == newUser.TCKimlik);

                    if (user.Count() < 1)
                    {
                        if (string.IsNullOrEmpty(newUser.Sifre))
                        {
                            newUser.Sifre = newUser.TCKimlik.ToString();
                        }

                        userRepository.Add(newUser);
                        result = new Result(SystemRess.Messages.basarili_kayit.ToString(), SystemRess.Messages.basarili_durum.ToString());
                        return result;
                    }
                    else
                    {
                        result = new Result(SystemRess.Messages.hata_ayniTcSistemdeMevcut.ToString(), SystemRess.Messages.hatali_durum.ToString());
                        return result;
                    }
                }
                catch (Exception)
                {
                    result = new Result(SystemRess.Messages.hatali_kayit.ToString(), SystemRess.Messages.hatali_durum.ToString());
                    return result;
                }
            }
        }
开发者ID:sakurahoshi,项目名称:appointment,代码行数:33,代码来源:UserManager.cs


注:本文中的Repository.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。