public async Task <ActionResult <V1DTO.GiftDTO> > PostGift(V1DTO.ArchivedGiftDTO archivedGiftDTO) { if (archivedGiftDTO.GiftId.Equals(Guid.Empty) || archivedGiftDTO.UserGiverId.Equals(Guid.Empty)) { return(BadRequest(new V1DTO.MessageDTO($"Could not find gift with id {archivedGiftDTO.GiftId.ToString()}"))); } // Make sure target gift exists and is in archived status var targetGift = await _bll.Gifts.GetArchivedForUserAsync(archivedGiftDTO.GiftId, User.UserGuidId()); if (targetGift == null) { return(NotFound(new V1DTO.MessageDTO($"Could not find gift with id {archivedGiftDTO.GiftId.ToString()}"))); } // Add new gift based on archived gift var archivedGiftBLL = _mapper.MapArchivedGiftDTOToBLL(archivedGiftDTO); var newGift = _mapper.Map(await _bll.Gifts.ReactivateArchivedAsync(archivedGiftBLL, User.UserGuidId())); if (newGift == null) { return(NotFound(new V1DTO.MessageDTO($"Could not find gift with id {archivedGiftDTO.GiftId.ToString()}"))); } // Save to db await _bll.SaveChangesAsync(); // Send back updated Gift return(CreatedAtAction( "GetPersonalGift", new { id = archivedGiftBLL.GiftId, version = HttpContext.GetRequestedApiVersion()?.ToString() ?? "0" }, newGift )); }
public async Task <IActionResult> PutPendingArchivedGift(Guid giftId, V1DTO.ArchivedGiftDTO archivedGiftDTO) { // Don't allow wrong data if (archivedGiftDTO.GiftId.Equals(Guid.Empty) || archivedGiftDTO.UserGiverId.Equals(Guid.Empty) || giftId != archivedGiftDTO.GiftId) { return(BadRequest(new V1DTO.MessageDTO($"Could not find gift with id {giftId.ToString()} or {archivedGiftDTO.GiftId}"))); } // Make sure target gift exists and is in pending archival status var targetGift = await _bll.Gifts.GetPendingArchivedForUserAsync(giftId, User.UserGuidId()); if (targetGift == null) { return(NotFound(new V1DTO.MessageDTO($"Could not find gift with id {giftId.ToString()}"))); } // Confirm getting this gift / archive it var confirmedArchivedGift = _mapper.Map(await _bll.Gifts.ConfirmPendingArchivedAsync(_mapper.MapArchivedGiftDTOToBLL(archivedGiftDTO), User.UserGuidId())); if (confirmedArchivedGift == null) { _logger.LogError($"EDIT. No such pending received Gift: {archivedGiftDTO.GiftId}, user: {User.UserGuidId().ToString()}"); return(NotFound(new V1DTO.MessageDTO($"No pending received Gift found for id {giftId.ToString()}"))); } // Save updates to db await _bll.SaveChangesAsync(); return(NoContent()); }
public async Task <ActionResult <V1DTO.GiftDTO> > DeletePendingArchivedGift(Guid giftId, V1DTO.ArchivedGiftDTO archivedGiftDTO) { // Don't allow wrong data if (archivedGiftDTO.GiftId.Equals(Guid.Empty) || archivedGiftDTO.UserGiverId.Equals(Guid.Empty) || giftId != archivedGiftDTO.GiftId) { return(BadRequest(new V1DTO.MessageDTO($"Could not find gift with id {giftId.ToString()} or {archivedGiftDTO.GiftId}"))); } // Deny getting gift and reactivate it instead var reactivatedGift = _mapper.Map(await _bll.Gifts.DenyPendingArchivedAsync(_mapper.MapArchivedGiftDTOToBLL(archivedGiftDTO), User.UserGuidId())); if (reactivatedGift == null) { _logger.LogError($"DELETE. No such reservedGift: {giftId.ToString()}, user: {User.UserGuidId().ToString()}"); return(NotFound(new V1DTO.MessageDTO($"ReservedGift with id {giftId.ToString()} not found"))); } // Save updates to db await _bll.SaveChangesAsync(); // Send back updated Gift with additional info, not deleted ReservedGift (it is just an implementation detail) return(Ok(reactivatedGift)); }
public async Task <ActionResult <V1DTO.GiftDTO> > DeleteArchivedGift(Guid giftId, V1DTO.ArchivedGiftDTO archivedGiftDTO) { // Don't allow wrong data if (archivedGiftDTO.GiftId.Equals(Guid.Empty) || archivedGiftDTO.UserGiverId.Equals(Guid.Empty) || giftId != archivedGiftDTO.GiftId) { return(BadRequest(new V1DTO.MessageDTO($"Could not find archived gift with id {giftId.ToString()} or {archivedGiftDTO.GiftId}"))); } // Delete archived gift var deletedArchivedGift = _mapper.Map(await _bll.Gifts.DeleteArchivedAsync(_mapper.MapArchivedGiftDTOToBLL(archivedGiftDTO), User.UserGuidId())); if (deletedArchivedGift == null) { return(NotFound(new V1DTO.MessageDTO($"Could not find archived gift with id {giftId.ToString()}"))); } // Save updates to db await _bll.SaveChangesAsync(); // Send back updated Gift with additional info, not deleted ReservedGift (it is just an implementation detail) return(Ok(deletedArchivedGift)); }