コード例 #1
0
        public bool DeleteCounty(County county)
        {
            if (county.Locality.Count == 0)
            {
                using (var ctx = new SocializRContext())
                {
                    county = ctx.County.Include(c => c.Locality).FirstOrDefault(c => c.Id == county.Id);
                }
            }

            if (county.Locality.Count != 0)
            {
                return(false);
            }
            if (user.isAdmin())
            {
                using (var ctx = new SocializRContext())
                {
                    ctx.County.Remove(county);
                    ctx.SaveChanges();
                    ctx.SaveChanges();
                }
            }
            return(false);
        }
コード例 #2
0
 public bool AddCounty(County newCounty)
 {
     if (user.isAdmin())
     {
         using (var ctx = new SocializRContext())
         {
             ctx.County.Add(newCounty);
             ctx.SaveChanges();
             return(true);
         }
     }
     return(false);
 }
コード例 #3
0
 public bool DeleteLocality(Locality locality)
 {
     if (user.isAdmin())
     {
         using (var ctx = new SocializRContext())
         {
             ctx.Locality.Remove(locality);
             ctx.SaveChanges();
             return(true);
         }
     }
     return(false);
 }
コード例 #4
0
 public bool EditCounty(County pre, County post)
 {
     if (user.isAdmin())
     {
         using (var ctx = new SocializRContext())
         {
             ctx.County.Update(pre);
             if (pre.Name != post.Name)
             {
                 pre.Name = post.Name;
             }
             ctx.SaveChanges();
             return(true);
         }
     }
     return(false);
 }
コード例 #5
0
 public bool EditLocality(Locality pre, Locality post)
 {
     if (user.isAdmin())
     {
         using (var ctx = new SocializRContext())
         {
             ctx.Locality.Update(pre);
             if (pre.Name != post.Name)
             {
                 pre.Name = post.Name;
             }
             if (pre.CountyId != post.CountyId)
             {
                 pre.CountyId = post.CountyId; pre.County = post.County;
             }
             ctx.Locality.Update(pre);
             ctx.SaveChanges();
             return(true);
         }
     }
     return(false);
 }
コード例 #6
0
 public BaseRepository(SocializRContext context)
 {
     Context = context;
 }
コード例 #7
0
ファイル: BaseUnitOfWork.cs プロジェクト: Andrei243/SocializR
 public BaseUnitOfWork(SocializRContext context)
 {
     DbContext = context;
 }