Exemple #1
0
        public ActionResult AddNew()
        {
            var model = new RoleModel
            {
                Permissions = LoadRolePermissions(Guid.Empty)
            };

            return JsonObject(true, string.Empty, new
            {
                html = PartialViewToString("_roleInfo", model)
            });
        }
Exemple #2
0
        public ActionResult Save(RoleModel model)
        {
            if (model.IsNew && !CanAdd)
            {
                return GetAddDeniedResult();
            }

            if (!model.IsNew && !CanUpdate)
            {
                return GetUpdateDeniedResult();
            }

            if (!ModelState.IsValid) return JsonObject(false, GetModelStateErrors());

            var role = model.Map<RoleModel, Role>();
            role.Name = role.Name.ToStr().Trim();

            if (role.IsNew)
            {
                role.InitId();
            }

            var result = ServiceHelper.Role.ExecuteDispose(s => s.SaveRole(new SaveRequest
            {
                Entity = role
            }));

            if (!result.Success)
            {
                var msg = result.Messages.FirstOrDefault();
                return JsonObject(false, string.IsNullOrWhiteSpace(msg)
                    ? BackendMessage.ErrorOccure : msg.GetServiceMessageRes());
            }

            SendNotification(NotifyType.Success, BackendMessage.SaveDataSuccess);

            return JsonObject(true, string.Empty);
        }