コード例 #1
0
        public ActionResult Create(DepartmentDTO entity)
        {
            int errors = 0;
            string message = string.Empty;

            if (Const.IsNullOrEmpty(entity.Name))
            {
                errors++;
                message = "部门名称不能为空。<br/>";
            }

            using (DataClassesDataContext data = new DataClassesDataContext())
            {
                if (data.DepartmentDTO.Where(u => u.ID == entity.ID).Count() > 0)
                {
                    errors++;
                    message = entity + " 部门已经存在。<br/>";
                }

                if (errors == 0)
                {
                    data.DepartmentDTO.InsertOnSubmit(entity);
                    data.SubmitChanges();
                }
            }

            return Json(new { success = (errors == 0), message = message }, JsonRequestBehavior.AllowGet);
        }
コード例 #2
0
        public ActionResult Update(DepartmentDTO entity)
        {
            try
            {
                if (entity.ID == 1)
                {
                    return Json(new { success = false, message = "默认部门不能修改。<br/>" }, JsonRequestBehavior.AllowGet);
                }

                int errors = 0;
                string message = string.Empty;

                if (Const.IsNullOrEmpty(entity.Name))
                {
                    errors++;
                    message = "部门名称不能为空。<br/>";
                }

                using (DataClassesDataContext data = new DataClassesDataContext())
                {
                    var items = data.DepartmentDTO.Where(u => u.ID == entity.ID)
                        .ToList();

                    if (items.Count == 0)
                    {
                        errors++;
                        message = entity.Name + " 部门不存在。<br/>";
                    }

                    if (errors == 0)
                    {
                        var e = items.First();

                        e.Name = entity.Name;
                        e.Description = entity.Description;

                        data.SubmitChanges();
                    }
                }

                return Json(new { success = (errors == 0), message = message }, JsonRequestBehavior.AllowGet);
            }
            catch
            {
                return View();
            }
        }
コード例 #3
0
 partial void UpdateDepartmentDTO(DepartmentDTO instance);
コード例 #4
0
 partial void DeleteDepartmentDTO(DepartmentDTO instance);
コード例 #5
0
 partial void InsertDepartmentDTO(DepartmentDTO instance);