Esempio n. 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);
        }
Esempio n. 2
0
        public new BLLAppDTO.CampaignBLL Add(BLLAppDTO.CampaignBLL bllCampaign, object?userId = null)
        {
            // UserId is mandatory for adding Campaign
            if (userId == null)
            {
                throw new ArgumentNullException(nameof(userId));
            }

            // Add new Campaign
            var dalCampaign        = Mapper.Map(bllCampaign);
            var dalCampaignTracked = UOW.Campaigns.Add(dalCampaign);

            UOW.AddToEntityTracker(dalCampaignTracked, bllCampaign);
            var bllNewCampaign = Mapper.Map(dalCampaignTracked);

            // Add new UserCampaign. TODO: Should be done via EF probably somehow
            var userIdGuid      = new Guid(userId.ToString());
            var bllUserCampaign = new BLLAppDTO.UserCampaignBLL()
            {
                AppUserId  = userIdGuid,
                CampaignId = bllNewCampaign.Id
            };
            var dalUserCampaign        = Mapper.MapUserCampaignToDAL(bllUserCampaign);
            var dalUserCampaignTracked = UOW.UserCampaigns.Add(dalUserCampaign);

            UOW.AddToEntityTracker(dalUserCampaignTracked, bllUserCampaign);
            Mapper.MapUserCampaignToBLL(dalUserCampaignTracked);

            return(bllNewCampaign);
        }
Esempio n. 3
0
        public override Item Add(Item entity)
        {
            var dalEntity        = Mapper.Map(entity);
            var trackedDALEntity = Repository.Add(dalEntity);

            UOW.AddToEntityTracker(trackedDALEntity, entity);
            var result = Mapper.Map(trackedDALEntity);

            if (entity.Categories == null)
            {
                return(result);
            }
            foreach (var categoryId in entity !.Categories)
            {
                var itemCategory = new ItemCategory
                {
                    ItemId     = entity.Id,
                    CategoryId = categoryId
                };
                UOW.ItemCategories.Add(itemCategory);
            }


            return(result);
        }
Esempio n. 4
0
        public override Category Add(Category entity)
        {
            var dalEntity        = Mapper.Map(entity);
            var trackedDALEntity = Repository.Add(dalEntity);

            UOW.AddToEntityTracker(trackedDALEntity, entity);
            var result = Mapper.Map(trackedDALEntity);

            return(result);
        }
Esempio n. 5
0
        // Creating cart
        public Cart CreateCart(Guid userId)
        {
            var cart = new Cart
            {
                UserId = userId,
            };
            var dalEntity        = Mapper.Map(cart);
            var trackedDALEntity = Repository.Add(dalEntity);

            UOW.AddToEntityTracker(trackedDALEntity, cart);
            var result = Mapper.Map(trackedDALEntity);

            return(result);
        }
Esempio n. 6
0
        /** Initial profile for a new user with no existing profiles */
        private BLLAppDTO.ProfileBLL AddDefaultProfile(Guid userId, BLLAppDTO.WishlistBLL wishlist)
        {
            var defaultProfileBLL = new BLLAppDTO.ProfileBLL
            {
                AppUserId = userId,
                Wishlist  = wishlist
            };
            // Add
            var defaultProfileDAL        = Mapper.Map(defaultProfileBLL);
            var defaultProfileDALTracked = UOW.Profiles.Add(defaultProfileDAL);

            // Track
            UOW.AddToEntityTracker(defaultProfileDALTracked, defaultProfileBLL);
            return(defaultProfileBLL);
        }
Esempio n. 7
0
        // TODO: FIX! Wishlist is being added twice (with different id). This will ruin interacting with gifts unless the wrong one is deleted first.
        /** Initial wishlist for a new user with no existing profiles */
        private BLLAppDTO.WishlistBLL AddDefaultWishlist(Guid userId)
        {
            var defaultWishlistBLL = new BLLAppDTO.WishlistBLL
            {
                AppUserId = userId,
                Comment   = "Default profile Wishlist"
            };
            // Add
            var defaultWishlistDAL        = Mapper.MapWishlistToDAL(defaultWishlistBLL);
            var defaultWishlistDALTracked = UOW.Wishlists.Add(defaultWishlistDAL);

            // Track
            UOW.AddToEntityTracker(defaultWishlistDALTracked, defaultWishlistBLL);
            return(defaultWishlistBLL);
        }
Esempio n. 8
0
        public Delivery CreateDelivery(Delivery entity, ICollection <ItemInCart> items, object?userId = null)
        {
            var dalEntity        = Mapper.Map(entity);
            var trackedDALEntity = Repository.Add(dalEntity);

            UOW.AddToEntityTracker(trackedDALEntity, entity);
            var result = Mapper.Map(trackedDALEntity);

            foreach (var item in items)
            {
                UOW.ItemDeliveryRepository.Add(new ItemDelivery
                {
                    ItemId     = item.ItemId,
                    DeliveryId = entity.Id
                });
            }



            return(result);
        }
Esempio n. 9
0
        /**
         * Add a new friendship with pending status
         * @param userId is mandatory and represents current user's Id
         */
        public new async Task <BLLAppDTO.FriendshipBLL> Add(BLLAppDTO.FriendshipBLL entity, object?userId = null)
        {
            // UserId is mandatory for adding Friendship
            if (userId == null)
            {
                throw new ArgumentNullException(nameof(userId));
            }

            // Check if relationship already exists
            var userGuidId = new Guid(userId.ToString());
            var friendId   = entity.AppUser2Id == userGuidId ? entity.AppUser1Id : entity.AppUser2Id;

            var existingFriendship = await UOW.Friendships.GetForUserAsync(userGuidId, friendId, true);

            var existingPendingRequest = await UOW.Friendships.GetForUserAsync(userGuidId, friendId, false);

            // TODO: Handle pending relationship differently, confirm it or something in case it is received.
            if (existingFriendship != null || existingPendingRequest != null)
            {
                // return new BLLAppDTO.FriendshipBLL();
                throw new NotSupportedException($"Could not add friendship - relationship between users {userGuidId.ToString()} {entity.AppUser2Id} already exists");
            }

            // Add new UserNotification for the friend (about friend request)
            var userNotificationBLL = new BLLAppDTO.UserNotificationBLL
            {
                AppUserId      = friendId,
                NotificationId = new Guid(_friendRequestNotificationId),
                IsActive       = true
            };
            var userNotificationDAL = UOW.UserNotifications.Add(Mapper.MapUserNotificationBLLToDAL(userNotificationBLL));

            UOW.AddToEntityTracker(userNotificationDAL, userNotificationBLL);
            Mapper.MapUserNotificationDALToBLL(userNotificationDAL);

            // Add new relationship with pending status
            entity.IsConfirmed = false;
            entity.AppUser1Id  = userGuidId;
            return(base.Add(entity, userId));
        }
Esempio n. 10
0
        /** Add new entry to ReservedGifts table */
        private BLLAppDTO.ReservedGiftResponseBLL?AddReservedGift(Guid giftId, Guid userId, Guid receiverId)
        {
            // Create
            var reservedGiftBLL = new BLLAppDTO.ReservedGiftFullBLL
            {
                StatusId       = new Guid(_reservedId),
                ActionTypeId   = new Guid(_archivedId),
                GiftId         = giftId,
                UserGiverId    = userId,
                UserReceiverId = receiverId,
                ReservedFrom   = DateTime.UtcNow
            };
            // Add
            var newReservedGift = UOW.ReservedGifts.Add(Mapper.MapReservedGiftFullToDAL(reservedGiftBLL), userId);

            // Track
            UOW.AddToEntityTracker(newReservedGift, reservedGiftBLL);
            // Check added data
            var isReservationSuccessful = reservedGiftBLL.GiftId == giftId;

            return(newReservedGift != null && isReservationSuccessful?Mapper.MapReservedGiftFullToResponse(reservedGiftBLL) : null);
        }
Esempio n. 11
0
        public BLLAppDTO.DonateeBLL Add(BLLAppDTO.DonateeBLL bllDonatee, Guid campaignId, Guid userId)
        {
            if (campaignId == null)
            {
                throw new ArgumentNullException(nameof(campaignId));
            }
            if (userId == null)
            {
                throw new ArgumentNullException(nameof(userId));
            }
            // Check if Campaign exists and current user is the owner of it
            var isUserCurrentCampaignOwner = UOW.UserCampaigns.FirstOrDefaultAsync(campaignId, userId);

            // Add new Donatee
            if (isUserCurrentCampaignOwner.Result != null)
            {
                throw new InvalidOperationException($"User {userId} not allowed to add this donatee");
            }

            var dalDonatee        = Mapper.Map(bllDonatee);
            var dalDonateeTracked = UOW.Donatees.Add(dalDonatee);

            UOW.AddToEntityTracker(dalDonateeTracked, bllDonatee);
            var bllNewDonatee = Mapper.Map(dalDonateeTracked);

            // Add new CampaignDonatee
            var bllCampaignDonatee = new BLLAppDTO.CampaignDonateeBLL()
            {
                CampaignId = campaignId,
                DonateeId  = bllNewDonatee.Id
            };
            var dalCampaignDonatee        = Mapper.MapCampaignDonateeToDAL(bllCampaignDonatee);
            var dalCampaignDonateeTracked = UOW.CampaignDonatees.Add(dalCampaignDonatee);

            UOW.AddToEntityTracker(dalCampaignDonateeTracked, bllCampaignDonatee);
            Mapper.MapCampaignDonateeToBLL(dalCampaignDonateeTracked);

            return(bllNewDonatee);
        }
Esempio n. 12
0
        /** Add new entry to ArchivedGifts table */
        private BLLAppDTO.ArchivedGiftResponseBLL?AddArchivedGift(Guid giftId, Guid userId, Guid receiverId)
        {
            // Create
            var archivedGiftBLL = new BLLAppDTO.ArchivedGiftFullBLL
            {
                StatusId       = new Guid(_archivedId),
                ActionTypeId   = new Guid(_activeId),
                GiftId         = giftId,
                UserGiverId    = userId,
                UserReceiverId = receiverId,
                DateArchived   = DateTime.UtcNow,
                IsConfirmed    = false
            };
            // Add
            var newArchivedGift = UOW.ArchivedGifts.Add(Mapper.MapArchivedGiftFullToDAL(archivedGiftBLL), userId);

            // Track
            UOW.AddToEntityTracker(newArchivedGift, archivedGiftBLL);
            // Check added data
            var isArchivalSuccessful = archivedGiftBLL.GiftId == giftId;

            return(newArchivedGift != null && isArchivalSuccessful?Mapper.MapArchivedGiftFullToResponse(archivedGiftBLL) : null);
        }
Esempio n. 13
0
        /**
         * Change pending friendship to confirmed status
         * @param userId is mandatory and represents current user's Id
         */
        public new async Task <BLLAppDTO.FriendshipBLL> UpdateAsync(BLLAppDTO.FriendshipBLL entity, object?userId = null)
        {
            // UserId is mandatory for updating Friendship
            if (userId == null)
            {
                throw new ArgumentNullException(nameof(userId));
            }
            // Add new UserNotification for the friend (about acceptance)
            var userNotificationBLL = new BLLAppDTO.UserNotificationBLL
            {
                AppUserId      = entity.AppUser2Id,
                NotificationId = new Guid(_friendshipApprovedNotificationId),
                IsActive       = true
            };
            var userNotificationDAL = UOW.UserNotifications.Add(Mapper.MapUserNotificationBLLToDAL(userNotificationBLL));

            UOW.AddToEntityTracker(userNotificationDAL, userNotificationBLL);
            Mapper.MapUserNotificationDALToBLL(userNotificationDAL);

            // Update relationship to confirmed status
            entity.IsConfirmed = true;
            entity.AppUser1Id  = new Guid(userId.ToString());
            return(await base.UpdateAsync(entity, userId));
        }