Esempio n. 1
0
        public ActionResult Create(RoleDTO entity)
        {
            int errors = 0;
            string message = string.Empty;

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

            if (Const.IsNullOrEmpty(entity.Code))
            {
                errors++;
                message = "角色编码不能为空。<br/>";
            }

            using (DataClassesDataContext data = new DataClassesDataContext())
            {
                if (data.RoleDTO.Where(u => u.Code == entity.Code).Count() > 0)
                {
                    errors++;
                    message = entity + " 角色已经存在。<br/>";
                }

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

            return Json(new { success = (errors == 0), message = message }, JsonRequestBehavior.AllowGet);
        }
Esempio n. 2
0
        public ActionResult Update(RoleDTO entity)
        {
            if (entity.Code == "Administrator")
            {
                return Json(new { success = false, message = "系统管理员不能修改。<br/>" }, JsonRequestBehavior.AllowGet);
            }

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

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

            if (Const.IsNullOrEmpty(entity.Code))
            {
                errors++;
                message = "角色编码不能为空。<br/>";
            }

            using (DataClassesDataContext data = new DataClassesDataContext())
            {
                var items = data.RoleDTO.Where(u => u.Code == entity.Code)
                    .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);
        }
 partial void UpdateRoleDTO(RoleDTO instance);
 partial void DeleteRoleDTO(RoleDTO instance);
 partial void InsertRoleDTO(RoleDTO instance);