public async Task <IActionResult> Post([FromBody] LockInsertDto lockDto) { if (ModelState.IsValid) { try { var domainLock = lockDto.ToDomain(); var created = await _lockRepository.InsertAsync(domainLock); var createdDto = created.ToDto(); createdDto.State = LockState.Undefined; return(CreatedAtAction(nameof(Get), new { id = created.Id }, createdDto)); } catch (Exception e) { _logger.LogError($"An error occured adding new lock with given exception: {e}"); return(e.Handle()); } } else { return(BadRequest(ModelState)); } }
public static Lock ToDomain(this LockInsertDto dto) { return(new Lock { Title = dto.Title, Description = dto.Description, SiteId = dto.SiteId }); }