Пример #1
0
        public IHttpActionResult Put(string id, [FromBody] UpdateUserModule model)
        {
            var blModel = new BL.Models.UpdateUserModule()
            {
                UserId     = User.Identity.GetUserId(),
                ModuleId   = id,
                ModuleName = model.Name
            };

            var errors = new List <string>();

            UserModuleService.Update(blModel, new ValidationErrors(errors));
            if (errors.Count != 0)
            {
                return(new ServiceErrorsResult(errors));
            }
            else
            {
                return(this.StatusCode(HttpStatusCode.NoContent));
            }
        }
Пример #2
0
        public void Update(UpdateUserModule model, IValidationErrors errors)
        {
            if (!model.Validate(errors))
            {
                return;
            }

            var userModule = UnitOfWork.UserModules.FirstOrDefault(x => x.UserId == model.UserId && x.ModuleId == model.ModuleId);

            if (userModule == null)
            {
                throw new Exception("User module not found");
            }

            if (userModule.Permission == Permissions.Prohibit)
            {
                throw new Exception("Access denied");
            }

            model.MapTo(userModule);
            UnitOfWork.SaveChanges();
        }