Esempio n. 1
0
        public IHttpActionResult Put(int roleId, RoleWriteModel model)
        {
            if (string.IsNullOrWhiteSpace(model.CodeName))
            {
                return(BadRequest("No codename provided."));
            }

            if (string.IsNullOrWhiteSpace(model.DisplayName))
            {
                return(BadRequest("No display name provided."));
            }

            var role = _roleRepository.FindById(roleId);

            if (role == null)
            {
                return(NotFound());
            }

            _roleMapper.Map(model, role);

            _roleRepository.Save(role);

            return(NoContent());
        }
Esempio n. 2
0
        public IHttpActionResult Post(RoleWriteModel model)
        {
            if (string.IsNullOrWhiteSpace(model.CodeName))
            {
                return(BadRequest("No codename provided."));
            }

            if (string.IsNullOrWhiteSpace(model.DisplayName))
            {
                return(BadRequest("No display name provided."));
            }

            var role = _roleFactory.CreateRole(model.CodeName, model.DisplayName);

            _roleMapper.Map(model, role);

            _roleRepository.Save(role);

            var result = Mapper.Map <RoleReadModel>(role);

            return(CreatedAtRoute("GetRole", new { roleId = role.Id }, result));
        }
Esempio n. 3
0
 public void Map(RoleWriteModel model, Role entity)
 {
     entity.CodeName    = model.CodeName;
     entity.DisplayName = model.DisplayName;
 }