Esempio n. 1
0
        public async Task <ActionResult <V1DTO.GiftDTO> > PostReservedGift(V1DTO.ReservedGiftDTO reservedGiftDTO)
        {
            if (reservedGiftDTO.GiftId.Equals(Guid.Empty) || reservedGiftDTO.UserReceiverId.Equals(Guid.Empty))
            {
                return(BadRequest(new V1DTO.MessageDTO($"Could not find gift with id {reservedGiftDTO.GiftId.ToString()}")));
            }
            var bllEntity = _mapper.MapReservedGiftDTOToBLL(reservedGiftDTO);
            // Reserve gift
            var giftDTO = _mapper.Map(await _bll.Gifts.MarkAsReservedAsync(bllEntity, User.UserGuidId()));
            // Save to db
            await _bll.SaveChangesAsync();

            // Send back updated Gift with additional info, not created ReservedGift (it is just an implementation detail)
            return(CreatedAtAction(
                       "GetReservedGift",
                       new { id = bllEntity.GiftId, version = HttpContext.GetRequestedApiVersion()?.ToString() ?? "0" },
                       giftDTO
                       ));
        }
Esempio n. 2
0
        public async Task <IActionResult> PutReservedGift(Guid giftId, V1DTO.ReservedGiftDTO reservedGiftDTO)
        {
            // Don't allow wrong data
            if (reservedGiftDTO.GiftId.Equals(Guid.Empty) || reservedGiftDTO.UserReceiverId.Equals(Guid.Empty) ||
                giftId != reservedGiftDTO.GiftId)
            {
                return(BadRequest(new V1DTO.MessageDTO($"Could not find gift with id {giftId.ToString()} or {reservedGiftDTO.GiftId}")));
            }
            // Mark gifted and archive
            var giftDTO = _mapper.Map(await _bll.Gifts.MarkAsGiftedAsync(_mapper.MapReservedGiftDTOToBLL(reservedGiftDTO), User.UserGuidId()));

            if (giftDTO == null)
            {
                _logger.LogError($"EDIT. No such reserved Gift: {reservedGiftDTO.GiftId}, user: {User.UserGuidId().ToString()}");
                return(NotFound(new V1DTO.MessageDTO($"No reserved Gift found for id {giftId.ToString()}")));
            }
            // Save updates to db
            await _bll.SaveChangesAsync();

            return(NoContent());
        }
Esempio n. 3
0
        public async Task <ActionResult <V1DTO.GiftDTO> > DeleteReservedGift(Guid giftId,
                                                                             V1DTO.ReservedGiftDTO reservedGiftDTO)
        {
            // Don't allow wrong data
            if (reservedGiftDTO.GiftId.Equals(Guid.Empty) || reservedGiftDTO.UserReceiverId.Equals(Guid.Empty) ||
                giftId != reservedGiftDTO.GiftId)
            {
                return(BadRequest(new V1DTO.MessageDTO($"Could not find gift with id {giftId.ToString()} or {reservedGiftDTO.GiftId}")));
            }
            // Cancel reservation, reactivate Gift
            var giftDTO = _mapper.Map(await _bll.Gifts.CancelReservationAsync(_mapper.MapReservedGiftDTOToBLL(reservedGiftDTO), User.UserGuidId()));

            if (giftDTO == 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(giftDTO));
        }