示例#1
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);
        }
示例#2
0
 public DALAppDTO.CampaignDonateeDAL MapCampaignDonateeToDAL(BLLAppDTO.CampaignDonateeBLL inObject)
 {
     return(Mapper.Map <DALAppDTO.CampaignDonateeDAL>(inObject));
 }