예제 #1
0
 public bool Delete(GovItemVM item)
 {
     var db = new GuvnerContext();
     var model = db.GovItems.FirstOrDefault(gi => gi.ID == item.ID);
     db.GovItems.Remove(model);
     return db.SaveChanges() != 0;
 }
예제 #2
0
파일: Program.cs 프로젝트: 1coguH/Guvner
        private static void test()
        {
            GuvnerContext db = new GuvnerContext();
            GovItem gi = new GovItem();
            gi.Text = "Human Resources";
            gi.GovItemType = (int)GovItemType.Focus;
            //gi.SomethingElse = "Whatever!";

            db.GovItems.Add(gi);
            db.SaveChanges();
        }
예제 #3
0
 public IEnumerable<GovItemVM> GetByType(int type)
 {
     var db = new GuvnerContext();
     var items = db.GovItems.Where(gi => gi.GovItemType == type).ToArray();
     if (items != null)
     {
         var vm = Mapper.Map<GovItem[], GovItemVM[]>(items);
         //vm.ParentList = GetParentAssociations((GovItemType)items.GovItemType);
         //vm.ChildList = GetChildAssociations((GovItemType)items.GovItemType);
         return vm;
     }
     return null;
 }
예제 #4
0
 public GovItemVM GetById(int id)
 {
     var db = new GuvnerContext();
     var item = db.GovItems.Include("Parent").Include("Children").FirstOrDefault(gi => gi.ID == id);
     if (item != null)
     {
         var vm = Mapper.Map(item, new GovItemVM());
         vm.ParentList = GetParentAssociations((GovItemType)item.GovItemType);
         vm.ChildList = GetChildAssociations((GovItemType)item.GovItemType);
         return vm;
     }
     return null;
 }
예제 #5
0
 public bool Save(GovItemVM item)
 {
     var db = new GuvnerContext();
     if (item.ID == 0)
     {
         var m = Mapper.Map<GovItemVM, GovItem>(item);
         db.GovItems.Add(m);
     }
     else
     {
         var model = db.GovItems.FirstOrDefault(gi => gi.ID == item.ID);
         Mapper.Map<GovItemVM, GovItem>(item, model);
     }
     return db.SaveChanges() != 0;
 }
예제 #6
0
 private List<GovItem> GetGovItemsByType(GovItemType type)
 {
     var db = new GuvnerContext();
     return db.GovItems.Where(g => g.GovItemType == (int)type).ToList();
 }