Пример #1
0
        public async Task <IActionResult> AddEmployee([FromBody] AddEmployeeRoleViewModel newRole)
        {
            if (!ModelState.IsValid)
            {
                var modelErrors = new List <string>();
                foreach (var modelState in ModelState.Values)
                {
                    foreach (var modelError in modelState.Errors)
                    {
                        modelErrors.Add(modelError.ErrorMessage);
                    }
                }
                return(BadRequest(new AddingResult {
                    Successful = false, Errors = modelErrors
                }));
            }
            var role = new EmployeeRole
            {
                Name        = newRole.Name,
                Description = newRole.Description
            };

            var successful = await _rolesService.AddRoleAsync(role);

            if (!successful)
            {
                return(BadRequest("Could not add role."));
            }
            return(Ok("Added role: " + role.Name));
        }
Пример #2
0
        public async Task <IActionResult> EditRole(string id, [FromBody] AddEmployeeRoleViewModel updatedRole)
        {
            var successful = await _rolesService
                             .UpdateRoleAsync(id, updatedRole);

            if (!successful)
            {
                return(BadRequest("Could not update employee."));
            }

            return(Ok("Updated employee of id: " + id));
        }