Пример #1
0
        public async Task <Department> UpdateDepartment([FromBody] Department department)
        {
            if (String.IsNullOrEmpty(department.Name))
            {
                throw new Exception("Не введено название отдела");
            }
            if (department.DepartmentId == 0)
            {
                throw new Exception("Нет индификатора отдела");
            }

            var departmentDb = await _departmentsService.ById(department.DepartmentId);

            if (departmentDb != null)
            {
                departmentDb.Name = department.Name;
                await _departmentsService.UpdateDepartment(departmentDb);
            }
            else
            {
                throw new Exception("Отдел не найден");
            }

            return(departmentDb);
        }