Exemple #1
0
        /** Add new entry to Gifts table - when reactivating an archived Gift (create a copy of archived entry) */
        private async Task <BLLAppDTO.GiftBLL?> AddNewGiftBasedOnArchivedEntry(BLLAppDTO.ArchivedGiftResponseBLL archivedGift, Guid userId)
        {
            // Get existing Gift in Archived status
            var existingGift = Mapper.Map((await UOW.Gifts.GetAllArchivedForUserAsync(userId))
                                          .SingleOrDefault(g => g.Id == archivedGift.GiftId));

            if (existingGift == null)
            {
                throw new NotSupportedException($"Could not reactivate gift {archivedGift.GiftId.ToString()}  - not found");
            }
            // Create a copy but make it Active. Added gifts are by default isPinned=false.
            var copyOfGift = new BLLAppDTO.GiftBLL
            {
                Name         = existingGift.Name,
                Description  = existingGift.Description,
                Image        = existingGift.Image,
                Url          = existingGift.Url,
                PartnerUrl   = existingGift.PartnerUrl,
                IsPartnered  = existingGift.IsPartnered,
                IsPinned     = false,
                WishlistId   = existingGift.WishlistId,
                ActionTypeId = new Guid(_reservedId),
                StatusId     = new Guid(_activeId)
            };
            // Add
            var newActiveGift = UOW.Gifts.Add(Mapper.Map(copyOfGift), userId);

            // Track
            UOW.AddToEntityTracker(newActiveGift, copyOfGift);
            // Check added data
            var isGiftInActiveStatus = copyOfGift.StatusId.ToString().Equals(_activeId);

            return(newActiveGift != null && isGiftInActiveStatus ? copyOfGift : null);
        }
Exemple #2
0
        /** Update gift to Archived status if corresponding ArchivedGift exists */
        private async Task <BLLAppDTO.GiftBLL> UpdateGiftStatusToArchivedAsync(BLLAppDTO.GiftBLL gift, BLLAppDTO.ArchivedGiftResponseBLL archivedGift, Guid userId)
        {
            var targetGiftId = gift.Id;

            if (targetGiftId != archivedGift.GiftId)
            {
                throw new NotSupportedException($"Could not reserve gift {targetGiftId.ToString()}  - data insertion fail");
            }
            // Update gift's status
            gift.StatusId = new Guid(_archivedId);
            var updatedGift = Mapper.Map(await UOW.Gifts.UpdateAsync(Mapper.Map(gift), archivedGift.UserReceiverId));

            if (updatedGift == null)
            {
                return(null !);
            }
            // Include new data regarding reservation in response
            updatedGift.ReservedFrom = archivedGift.DateArchived;
            updatedGift.UserGiverId  = userId;
            return(updatedGift);
        }