Example #1
0
 public void Add(Department entity)
 {
     using (var db = GetDataContext())
     {
         db.Department.Add(entity);
         db.SaveChanges();
     }
 }
 public ActionResult Edit(Department model)
 {
     if (string.IsNullOrEmpty(model.Name))
     {
         throw new ArgumentNullException("部门名称没有填写!");
     }
     Core.DepartmentManager.Save(model);
     return JsonSuccess(model);
 }
Example #3
0
 private List<Department> GetChildren(List<Department> list, Department parent)
 {
     var children = list.Where(e => e.ParentID == parent.ID).ToList();
     if (children.Count == 0) return children;
     foreach (var item in children)
     {
         item.Children = GetChildren(list, item);
     }
     return children;
 }
Example #4
0
 public void Update(Department entity)
 {
     using (var db = GetDataContext())
     {
         var toUpdae = db.Department.FirstOrDefault(e => e.ID == entity.ID);
         if (toUpdae == null)
         {
             throw new ArgumentException("departmentId参数错误");
         }
         db.Entry(toUpdae).CurrentValues.SetValues(entity);
         db.SaveChanges();
     }
 }
Example #5
0
        public void Save(Department model)
        {
            if (model == null)
            {
                throw new ArgumentException("department.Name is null");
            }

            if (model.ID > 0)
            {
                dao.Update(model);
            }
            else
            {
                dao.Add(model);
            }
            Core.AccountManager.RefreshCache();
        }