Ejemplo n.º 1
0
        public async Task <IActionResult> CreateDepartment([FromBody] Department department)
        {
            var d = new DbModels.Department()
            {
                Name = department.Name
            };

            var username = _userManager.GetUserName(HttpContext.User);

            _logger.LogInformation(LoggingEvents.InsertItem, "{username} creating department with name {name}", username, d.Name);

            var result = await _departmentService.CreateDepartmentAsync(d);

            if (result != null)
            {
                _logger.LogInformation(LoggingEvents.InsertItem, "{username} created department with name {name}", username, result.Name);
                return(CreatedAtAction(nameof(GetDepartments), new { departmentId = result.Id }, new Department(result)));
            }

            _logger.LogWarning(LoggingEvents.InsertItemFail, "{username} failed to create department with name {name}", username, d.Name);
            return(BadRequest());
        }
Ejemplo n.º 2
0
 public Department(DbModels.Department department)
 {
     Id   = department.Id;
     Name = department.Name;
 }