public async Task <ActionResult <V1DTO.InvitedUserDTO> > PostInvitedUser(V1DTO.InvitedUserDTO invitedUserDTO) { // Create invitedUser var bllEntity = _mapper.Map(invitedUserDTO); bllEntity.DateInvited = DateTime.Now; bllEntity.HasJoined = false; bllEntity.InvitorUserId = User.UserGuidId(); // Add to db _bll.InvitedUsers.Add(bllEntity); await _bll.SaveChangesAsync(); invitedUserDTO.Id = bllEntity.Id; return(CreatedAtAction( "GetPersonalInvitedUser", new { id = invitedUserDTO.Id, version = HttpContext.GetRequestedApiVersion()?.ToString() ?? "0" }, invitedUserDTO )); }
public async Task <IActionResult> PutInvitedUser(Guid id, V1DTO.InvitedUserDTO invitedUserDTO) { // Don't allow wrong data if (id != invitedUserDTO.Id) { return(BadRequest(new V1DTO.MessageDTO("id and invitedUser.id do not match"))); } var invitedUser = await _bll.InvitedUsers.FirstOrDefaultAsync(invitedUserDTO.Id, User.UserGuidId()); if (invitedUser == null) { _logger.LogError($"EDIT. No such invitedUser: {invitedUserDTO.Id}, user: {User.UserGuidId()}"); return(NotFound(new V1DTO.MessageDTO($"No InvitedUser found for id {id}"))); } // Update existing invitedUser await _bll.InvitedUsers.UpdateAsync(_mapper.Map(invitedUserDTO), User.UserId()); await _bll.SaveChangesAsync(); return(NoContent()); }