Save() public méthode

public Save ( ) : bool
Résultat bool
        public void TestMethod1()
        {
            using (SchoolContext ctx = new SchoolContext())
            {
                ctx.Configuration.LazyLoadingEnabled = false;
                //School s1 = new School() { Name = "Coopers", Address = "Royal Parade" };
                //EntityState st1 = ctx.Entry(s1).State;
                //ctx.Schools.Add(s1);

                //ctx.SaveChanges();

                School s2 = ctx.Schools.Include(x => x.Students).Where(x => x.Id == 1).FirstOrDefault();

                EntityState st2 = ctx.Entry(s2).State;
                s2.Name = "change";
                st2 = ctx.Entry(s2).State;
            }

            using (UnitOfWork uow = new UnitOfWork())
            {
                School s1 = uow.Repository<School>().GetByID(1);

                uow.Repository<School>().Insert(new School() { Name = "Coopers", Address = "Royal Parade" });
                uow.Save();
            }
        }
Exemple #2
0
        private void IninitialParam()
        {
            try
            {
                System.Collections.Generic.List <Models.DaysReView> lstDaysReView =
                    UnitOfWork.DaysReViewRepository.Get()
                    .ToList();



                if (lstDaysReView.Count > 0)
                {
                    TotalCountReView = lstDaysReView.Sum(p => p.TotalCount);
                }
                else
                {
                    TotalCountReView = 0;
                }

                string pp = Infrastructure.Utility.Now.AddDays(-1).ToShortDateString();
                if (lstDaysReView.Where(p => p.DateSatistic.ToShortDateString() == Infrastructure.Utility.Now.AddDays(-1).ToShortDateString()).Count() > 0)
                {
                    YesterDayCountReview = lstDaysReView.Where(p => p.DateSatistic.ToShortDateString() ==
                                                               Infrastructure.Utility.Now.AddDays(-1).ToShortDateString()).FirstOrDefault().TotalCount;
                }
                else
                {
                    YesterDayCountReview = 0;
                }

                if (lstDaysReView.Where(p => p.DateSatistic.ToShortDateString() == Infrastructure.Utility.Now.ToShortDateString()).Count() > 0)
                {
                    ToDayCountReview = lstDaysReView.Where(p => p.DateSatistic.ToShortDateString() == Infrastructure.Utility.Now.ToShortDateString())
                                       .FirstOrDefault()
                                       .TotalCount;

                    IdDay = lstDaysReView.Where(p => p.DateSatistic.ToShortDateString() == Infrastructure.Utility.Now.ToShortDateString())
                            .FirstOrDefault()
                            .Id;
                }
                else
                {
                    ToDayCountReview = 0;

                    IdDay = System.Guid.NewGuid();

                    Models.DaysReView oDaysReView = new Models.DaysReView()
                    {
                        Id           = IdDay,
                        TotalCount   = 0,
                        DateSatistic = Infrastructure.Utility.Now
                    };

                    UnitOfWork.DaysReViewRepository.Insert(oDaysReView);

                    UnitOfWork.Save();
                }

                OnlineCountReview = 0;

                ToDayCountReviewPage = 0;
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }