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


C# Repository.Update方法代码示例

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


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

示例1: RemindEndOfWeek

        public void RemindEndOfWeek(Reminder endOfWeekReminder)
        {
            var dateToday = DateTime.Now;
            TimeSpan accumulatedTime = new TimeSpan(0,0,0);

            if (dateToday.ToString("ddd") == "Mon" && dateToday.Hour == endOfWeekReminder.TimeOfActivation.Hour && dateToday.Minute == endOfWeekReminder.TimeOfActivation.Minute)
            {
                IRepository repo = new Repository();
                var startOfWeekTime = dateToday.AddDays(-4);

                var list = repo.GetByStartDate(startOfWeekTime, dateToday);

                foreach(SparkTask task in list)
                {
                    if (task.State != TaskState.reported){ accumulatedTime = accumulatedTime.Add(task.TimeElapsed); }
                }

                if (accumulatedTime >= new TimeSpan(36, 0, 0))
                {
                    ReminderEventArgs args = new ReminderEventArgs(endOfWeekReminder, new SparkTask());
                    reminderControl.OnEventHaveToReport(args);
                    endOfWeekReminder.TimeOfActivation = endOfWeekReminder.TimeOfActivation.AddHours(1);
                    repo.Update(endOfWeekReminder);
                    //event!
                }
            }
        }
开发者ID:hblanco-nearsoft,项目名称:ChronoSparkExtreme,代码行数:27,代码来源:ReportWeekReminder.cs

示例2: RemindStartOfWeek

        public void RemindStartOfWeek(Reminder startOfWeekReminder)
        {
            var dateToday = DateTime.Now;
            TimeSpan accumulatedTime = new TimeSpan(0, 0, 0);
            if (dateToday.ToString("ddd") == "Mon" && dateToday.Hour == startOfWeekReminder.TimeOfActivation.Hour && dateToday.Minute == startOfWeekReminder.TimeOfActivation.Minute ) //should get the hour from a reminder!dateToday.ToString("h tt") == "4 PM"
            {
                IRepository repo = new Repository();
                var startOfWeekTime = dateToday.AddDays(-7);
                //var dateTomorrow = dateToday.AddDays(1);

                var list = repo.GetByStartDate(startOfWeekTime, dateToday);

                foreach (SparkTask task in list)
                {
                    if(task.State != TaskState.reported){ accumulatedTime = accumulatedTime.Add(task.TimeElapsed); }
                }

                if (accumulatedTime >= new TimeSpan(36, 0, 0))
                {
                    ReminderEventArgs args = new ReminderEventArgs(startOfWeekReminder, new SparkTask()); //should be the reminder im using send the task can stay like this.
                    reminderControl.OnEventHaveToReport(args);
                    startOfWeekReminder.TimeOfActivation = startOfWeekReminder.TimeOfActivation.AddHours(1);
                    repo.Update(startOfWeekReminder);
                }

            }
        }
开发者ID:hblanco-nearsoft,项目名称:ChronoSparkExtreme,代码行数:27,代码来源:ReportWeekReminder.cs

示例3: Should_update_entity_using_single_context

        public void Should_update_entity_using_single_context()
        {
            Order toUpdate = null;

            try
            {
                // Get original  -- Arrange
                using (var context = new RepositoryTest())
                {
                    var repo = new Repository<Order>(context);

                    toUpdate = repo.GetById(10337);

                    // alter property and then update -- Act
                    toUpdate.ShipName = "abc";

                    repo.Update(toUpdate);
                }

                // Requery db to Assert that data updated
                using (var context = new RepositoryTest())
                {
                    var repo = new Repository<Order>(context);

                    var original = repo.GetById(10337);

                    Assert.AreEqual("abc", original.ShipName);
                }
            }
            finally
            {
                // Clean up the data so that its in the correct state
                TestScriptHelper.ResetShipName();
            }
        }
开发者ID:NathanGloyn,项目名称:Generic-Repository,代码行数:35,代码来源:When_updating_data.cs

示例4: Handle

        public Unit Handle(Repository repository)
        {
            var existing = repository.Get<Product>().Where(it => string.Compare(it.Name, Name, StringComparison.InvariantCultureIgnoreCase) == 0).First();
              existing.DecQuantity(Quantity);
              repository.Update(existing);

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

示例5: Edit

        public ActionResult Edit(Person new_person)
        {
            if (ModelState.IsValid) {
                var person_factory = new Repository<Person>();
                person_factory.Update(new_person);
            }

            return View();
        }
开发者ID:EnriqueVidal,项目名称:GetAJob,代码行数:9,代码来源:PeopleController.cs

示例6: Should_throw_exception_if_null_passed_in

        public void Should_throw_exception_if_null_passed_in()
        {
            using (var context = new RepositoryTest())
            {
                var repo = new Repository<Order>(context);

                Assert.Throws<ArgumentNullException>(() => repo.Update(null));
            }
        }
开发者ID:NathanGloyn,项目名称:Generic-Repository,代码行数:9,代码来源:When_updating_data.cs

示例7: TestUpdateWorks

        public void TestUpdateWorks()
        {
            Repository repository = new Repository(new SqlConnectionDev());
            Club club = new Club();
            club.clubId = 1;
            club.Name = "Stirling Kyokushin";

            bool result = repository.Update(club);
            Assert.That(result);
        }
开发者ID:chao226,项目名称:Dapper.Repository,代码行数:10,代码来源:UnitTest1.cs

示例8: Execute

        public void Execute(object state)
        {
            var logInfo = new LogInfo
            {
                MethodInstance = MethodBase.GetCurrentMethod(),
                ThreadInstance = Thread.CurrentThread
            };

            try
            {
                _log.Info("Scheduler Start: (AutoUpdateMonthlyRank)", logInfo);

                IRepository repo = new Repository();

                var iDay = DateTime.Today;

                var firstBetDate = repo.Single<Bet>(1).BetTime;

                while (!(iDay.Year <= firstBetDate.Year && iDay.Month < firstBetDate.Month))
                {
                    var winner = GamblerDW.GetTopGamblerMonthly(iDay, RankType.Winner);
                    var loser = GamblerDW.GetTopGamblerMonthly(iDay, RankType.Loser);
                    var rper = GamblerDW.GetTopGamblerMonthly(iDay, RankType.RP);

                    if (winner != null && loser != null)
                    {
                        var day = iDay;
                        var rank = repo.Query<Rank>(x => x.RankYear == day.Year && x.RankMonth == day.Month).FirstOrDefault();

                        if (rank != null)
                        {
                            //update
                            rank.Init(winner, loser, rper);

                            repo.Update(rank);
                        }
                        else
                        {
                            //insert
                            var instance = new Rank { RankYear = day.Year, RankMonth = day.Month };
                            instance.Init(winner, loser, rper);

                            repo.Insert(instance);
                        }
                    }
                    iDay = iDay.AddMonths(-1);
                }

                _log.Info("Scheduler End: (AutoUpdateMonthlyRank)", logInfo);
            }
            catch (Exception ex)
            {
                _log.Warn(ex, logInfo);
            }
        }
开发者ID:CyranoChen,项目名称:Arsenalcn,代码行数:55,代码来源:AutoUpdateMonthlyRank.cs

示例9: BasicCrud

        public void BasicCrud()
        {
            using (var trans = DataSource.BeginTransaction())
            {

                var repo = new Repository<Employee, int>(trans, EmployeeTableName);

                var emp1 = new Employee() { FirstName = "Tom", LastName = "Jones", Title = "President" };
                var echo1 = repo.Insert(emp1);

                Assert.AreNotEqual(0, echo1.EmployeeKey, "EmployeeKey was not set");
                Assert.AreEqual(emp1.FirstName, echo1.FirstName, "FirstName");
                Assert.AreEqual(emp1.LastName, echo1.LastName, "LastName");
                Assert.AreEqual(emp1.Title, echo1.Title, "Title");

                echo1.MiddleName = "G";
                repo.Update(echo1);

                var emp2 = new Employee() { FirstName = "Lisa", LastName = "Green", Title = "VP Transportation", ManagerKey = echo1.EmployeeKey };
                var echo2 = repo.Insert(emp2);
                Assert.AreNotEqual(0, echo2.EmployeeKey, "EmployeeKey was not set");
                Assert.AreEqual(emp2.FirstName, echo2.FirstName, "FirstName");
                Assert.AreEqual(emp2.LastName, echo2.LastName, "LastName");
                Assert.AreEqual(emp2.Title, echo2.Title, "Title");
                Assert.AreEqual(emp2.ManagerKey, echo2.ManagerKey, "ManagerKey");

                var list = repo.GetAll();
                Assert.IsTrue(list.Any(e => e.EmployeeKey == echo1.EmployeeKey), "Employee 1 is missing");
                Assert.IsTrue(list.Any(e => e.EmployeeKey == echo2.EmployeeKey), "Employee 2 is missing");

                var get1 = repo.Get(echo1.EmployeeKey.Value);
                Assert.AreEqual(echo1.EmployeeKey, get1.EmployeeKey);



                var whereSearch1 = repo.Query("FirstName = @FN", new { FN = "Tom" });
                Assert.IsTrue(whereSearch1.Any(x => x.EmployeeKey == echo1.EmployeeKey), "Emp1 should have been returned");
                Assert.IsTrue(whereSearch1.All(x => x.FirstName == "Tom"), "Checking for incorrect return values");

                var whereSearch2 = repo.Query(new { FirstName = "Tom" });
                Assert.IsTrue(whereSearch2.Any(x => x.EmployeeKey == echo1.EmployeeKey), "Emp1 should have been returned");
                Assert.IsTrue(whereSearch2.All(x => x.FirstName == "Tom"), "Checking for incorrect return values");


                repo.Delete(echo2.EmployeeKey.Value);
                repo.Delete(echo1.EmployeeKey.Value);

                var list2 = repo.GetAll();
                Assert.AreEqual(list.Count - 2, list2.Count);

                trans.Commit();
            }

        }
开发者ID:docevaad,项目名称:Chain,代码行数:54,代码来源:TransactionalRepositoryTests.cs

示例10: AutoUpdateMemberType_Test

        public void AutoUpdateMemberType_Test()
        {
            try
            {
                IRepository repo = new Repository();

                var mlist = repo.All<Member>().FindAll(x => (int)x.MemberType <= 2);
                var olist = repo.All<Order>().FindAll(x => x.IsActive);

                if (mlist.Count > 0 && olist.Count > 0)
                {
                    // Don't place LINQ to Foreach, first ToList(), then use list.FindAll to improve performance
                    foreach (var m in mlist)
                    {
                        MemberType type;
                        var list = olist.FindAll(x => x.MemberID == m.ID);

                        // Refresh the MemberType of instance
                        if (list.Count > 0)
                        {
                            if (list.Exists(x => x.OrderType == OrderBaseType.Ticket || x.OrderType == OrderBaseType.Travel))
                            {
                                type = MemberType.Match;
                            }
                            else if (list.Exists(x => x.OrderType == OrderBaseType.ReplicaKit ||
                                x.OrderType == OrderBaseType.Printing || x.OrderType == OrderBaseType.Wish))
                            {
                                type = MemberType.Buyer;
                            }
                            else
                            {
                                type = MemberType.None;
                            }
                        }
                        else
                        {
                            type = MemberType.None;
                        }

                        if (!m.MemberType.Equals(type))
                        {
                            m.MemberType = type;

                            repo.Update(m);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
开发者ID:CyranoChen,项目名称:Arsenalcn,代码行数:53,代码来源:AutoUpdateMemberTypeTest.cs

示例11: DataPortal_Update

 protected override void DataPortal_Update()
 {
     ExceptionManager.Process(
         () =>
             {
                 using (var repository = new Repository())
                 {
                     repository.Update(ToDTO(), false);
                     FieldManager.UpdateChildren(repository, CompanyID);
                     repository.Save();
                 }
             });
 }
开发者ID:Jaans,项目名称:csla,代码行数:13,代码来源:CompanyEdit.server.cs

示例12: TestKLineReadAndWrite

        public void TestKLineReadAndWrite()
        {
            StockKLine insertData = new StockKLine()
            {
                Amount = 123214124,
                Close = 19.96,
                Open = 19.05,
                High = 19.98,
                Low = 19.01,
                Time = DateTime.Now.Date,
                Volume = 32342352352
            };

            string fileName = "600036_2015.sdf";
            string fullPath = Path.Combine(directory, fileName);

            // Add
            using (IRepositoryContext context = ContextFactory.Create(ContextType.KLine, fullPath))
            {
                var repository = new Repository<StockKLine>(context);
                repository.Add(insertData);
                repository.UnitOfWork.Commit();
            }

            // Read
            StockKLine readData;
            using (IRepositoryContext context = ContextFactory.Create(ContextType.KLine, fullPath))
            {
                var repository = new Repository<StockKLine>(context);
                readData = repository.Get(insertData.Time);
            }
            Assert.IsNotNull(readData);
            Assert.AreEqual(insertData.Time, readData.Time);

            // update
            StockKLine updatedData = readData;
            updatedData.Open = 100;
            using (IRepositoryContext context = ContextFactory.Create(ContextType.KLine, fullPath))
            {
                var repository = new Repository<StockKLine>(context);
                repository.Update(updatedData);
                repository.UnitOfWork.Commit();
            }
            // Read
            using (IRepositoryContext context = ContextFactory.Create(ContextType.KLine, fullPath))
            {
                var repository = new Repository<StockKLine>(context);
                readData = repository.Get(insertData.Time);
            }
            Assert.IsTrue(readData.Open - 100 < 0.0000001);
        }
开发者ID:philfanzhou,项目名称:Pitman,代码行数:51,代码来源:SqlCeTest.cs

示例13: UpdateShouldWork

        public void UpdateShouldWork()
        {
            var cudGroup = new Repository<Group>(connectionString);

            var entity = new Group { Name = "Test", Description = "Abcd" };
            mongoDb.GetCollection(MongoDbConstants.Collections.Groups).Insert(entity);

            entity.Name = "Tito";
            //act
            cudGroup.Update(entity);

            mongoDb.GetCollection<Group>(MongoDbConstants.Collections.Groups)
                .FindOneById(entity.Id.Value.ToBson())
                .Name.Should().Be.EqualTo("Tito");
        }
开发者ID:jasondentler,项目名称:Hermes,代码行数:15,代码来源:CudGroupsTests.cs

示例14: UpdateGroup

        public MessageResultDto UpdateGroup(Guid id, string name)
        {
            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 == id);
                group.Name = name;
                groupRepository.Update(group);
                transaction.Commit();
            }
            return result;
        }
开发者ID:SadiqAhmed,项目名称:MyNotes,代码行数:15,代码来源:GroupStorageProxy.cs

示例15: Execute

        public void Execute(object state)
        {
            var logInfo = new LogInfo
            {
                MethodInstance = MethodBase.GetCurrentMethod(),
                ThreadInstance = Thread.CurrentThread
            };

            try
            {
                _log.Info("Scheduler Start: (AutoUpdateOrderType)", logInfo);

                IRepository repo = new Repository();

                var oList = repo.All<Order>();
                var oiList = repo.All<OrderItem>().FindAll(x => Product.Cache.Load(x.ProductGuid) != null);

                if (oList.Count > 0 && oiList.Count > 0)
                {
                    // Don't place LINQ to Foreach, first ToList(), then use list.FindAll to improve performance
                    foreach (var o in oList)
                    {
                        var list = oiList.FindAll(x => x.OrderID.Equals(o.ID));

                        // Refresh the OrderType of instance
                        if (list.Count > 0)
                        {
                            var type = Order.GetOrderTypeByOrderItems(list);

                            if (!o.OrderType.Equals(type))
                            {
                                o.OrderType = type;

                                repo.Update(o);
                            }
                        }
                    }
                }

                _log.Info("Scheduler End: (AutoUpdateOrderType)", logInfo);
            }
            catch (Exception ex)
            {
                _log.Warn(ex, logInfo);
            }
        }
开发者ID:CyranoChen,项目名称:Arsenalcn,代码行数:46,代码来源:AutoUpdateOrderType.cs


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