コード例 #1
0
        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));
            }
        }
コード例 #2
0
 public static Lock ToDomain(this LockInsertDto dto)
 {
     return(new Lock
     {
         Title = dto.Title,
         Description = dto.Description,
         SiteId = dto.SiteId
     });
 }