public async Task <IActionResult> PutPrivateMessage(Guid id, V1DTO.PrivateMessageDTO actionTypeDTO) { // Don't allow wrong data if (id != actionTypeDTO.Id) { return(BadRequest(new V1DTO.MessageDTO("id and actionType.id do not match"))); } var actionType = await _bll.PrivateMessages.FirstOrDefaultAsync(actionTypeDTO.Id, User.UserGuidId()); if (actionType == null) { _logger.LogError($"EDIT. No such actionType: {actionTypeDTO.Id}, user: {User.UserGuidId()}"); return(NotFound(new V1DTO.MessageDTO($"No PrivateMessage found for id {id}"))); } // Update existing actionType await _bll.PrivateMessages.UpdateAsync(_mapper.Map(actionTypeDTO), User.UserId()); await _bll.SaveChangesAsync(); return(NoContent()); }
public async Task <ActionResult <V1DTO.PrivateMessageDTO> > PostPrivateMessage(V1DTO.PrivateMessageDTO actionTypeDTO) { // Create actionType var bllEntity = _mapper.Map(actionTypeDTO); _bll.PrivateMessages.Add(bllEntity); await _bll.SaveChangesAsync(); actionTypeDTO.Id = bllEntity.Id; return(CreatedAtAction( "GetPrivateMessage", new { id = actionTypeDTO.Id, version = HttpContext.GetRequestedApiVersion()?.ToString() ?? "0" }, actionTypeDTO )); }