예제 #1
0
        public ActionResult Create(DepartmentViewModel model)
        {
            ServiceResult result = new ServiceResult();
            TempData["Service_Result"] = result;
            if (ModelState.IsValid)
            {
                try
                {
                    Department entity = new Department();
                    entity.Name = model.Name;
                    entity.Description = model.Description;
                    entity.Level = model.Level;
                    entity.PID = model.PID;
                    entity.Code = model.Code;
                    DepartmentService.Create(entity);
                    result.Message = "添加部门成功!";
                    LogHelper.WriteLog("添加部门成功");
                    return RedirectToAction("index");
                }
                catch (DbEntityValidationException ex)
                {
                    result.Message = Utilities.GetInnerMostException(ex);
                    result.AddServiceError(result.Message);
                    LogHelper.WriteLog("添加部门错误", ex);
                }
            }
            else
            {
                result.Message = "请检查表单是否填写完整!";
                result.AddServiceError("请检查表单是否填写完整!");

            }
            ViewBag.Data_PID = GetSelectList();
            return View(model);
        }
예제 #2
0
        public void Update(Department model)
        {
            var target = Find(model.ID);
            db.Attach<Department>(target);
            target.Description = model.Description;
            target.Name = model.Name;
            target.Code = model.Code;
            target.Level = model.Level;
            target.PID = model.PID;

            db.Commit();
        }
예제 #3
0
 public void Delete(Department model)
 {
     var target = Find(model.ID);
     db.Remove<Department>(target);
     db.Commit();
 }
예제 #4
0
 public void Create(Department model)
 {
     db.Add<Department>(model);
     db.Commit();
 }