Exemplo n.º 1
0
        public ActionResult Donate(DonateFormViewModel model)
        {
            var fundraiser = _fundraiserRepository.FindById(model.FundraiserId);
            var campaign   = _campaignRepository.FindById(fundraiser.CampaignId);

            if (model.DonationAmount > 0)
            {
                var chargeService = new StripeChargeService();
                var charge        = chargeService.Create(new StripeChargeCreateOptions()
                {
                    Amount      = model.DonationAmount * 100,
                    Currency    = "usd",
                    Description = fundraiser.Name,
                    SourceTokenOrExistingSourceId = model.StripeToken
                });
                string userid = null;
                if (User.Identity.IsAuthenticated)
                {
                    userid = User.Identity.GetUserId();
                }
                _donationRepository.Create(campaign, fundraiser, DonationStatus.Completed, model.DonationAmount, "usd", model.DonationAmount, userid, model.DonorDisplayName, charge.Id);
            }

            var fundraiserViewModel = AutoMapper.Mapper.Map <Fundraiser, FundraiserFormViewModel>(fundraiser);

            return(View("Thanks", fundraiserViewModel));
        }
Exemplo n.º 2
0
        protected override bool HandleCore(Donate request)
        {
            var fundraiser = _fundraiserRepository.FindById(request.FundraiserId);
            var campaign   = _campaignRepository.FindById(fundraiser.CampaignId);

            if (request.DonationAmount > 0)
            {
                try
                {
                    var chargeService = new StripeChargeService();
                    var charge        = chargeService.Create(new StripeChargeCreateOptions()
                    {
                        Amount      = request.DonationAmount * 100,
                        Currency    = "usd",
                        Description = fundraiser.Name,
                        SourceTokenOrExistingSourceId = request.StripeToken
                    });
                    var donation = _donationRepository.Create(campaign, fundraiser, DonationStatus.Completed, request.DonationAmount, "usd", request.DonationAmount, request.UserId, request.DonorDisplayName, charge.Id);

                    var integrationEvent = new DonationCreatedIntegrationEvent(donation.DonorUserId,
                                                                               donation.FundraiserId, donation.Amount, donation.DonorDisplayName);

                    _eventBus.Publish(integrationEvent); // not tested; maybe IEventBus should be named something else since EasyNetQ already has an IEventBus; perhaps Publish(e) should be Publish<T>(e)?
                }
                catch (InvalidOperationException)
                {
                    return(false); // maybe should return json with validation info?
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 3
0
        public void CreateDonations()
        {
            var donation = _donationRepository.Create(_testCampaign, null, DonationStatus.Pledged, 10.00, _testCampaign.DefaultCurrencyCode, 10.00, "001", "Alex", "001");

            Assert.IsTrue(donation.DonorDisplayName == "Alex", "donor name matches");
            Assert.IsTrue(donation.Status == DonationStatus.Pledged, "status is correct (Pledged)");
            Assert.IsTrue(donation.Id != null && donation.Id.ToString() != "00000000-0000-0000-0000-000000000000", "id is set");
            Console.WriteLine("donation.Id: " + donation.Id);

            var donation2 = _donationRepository.Create(_testCampaign, null, DonationStatus.Completed, 10.00, "NIO", 299.25, "002", "Test", "002");

            Assert.IsTrue(donation2.DonorDisplayName == "Test", "donor name matches");
            Assert.IsTrue(donation2.Status == DonationStatus.Completed, "status is correct (completed)");
            Assert.IsTrue(donation2.Id != null && donation2.Id.ToString() != "00000000-0000-0000-0000-000000000000", "id is set");
            Console.WriteLine("donation2.Id: " + donation2.Id);
        }
Exemplo n.º 4
0
        public Donation CreateDonation(Donation donation)
        {
            if (donation != null)
            {
                var donationDb = _donationRepository.Create(donation);

                return(donationDb);
            }
            return(null);
        }
Exemplo n.º 5
0
        public IActionResult Post([FromBody] DonationCreateDto donation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var donationEntity = _mapper.Map <Donation>(donation);

            _donationRepository.Create(donationEntity);
            if (!_donationRepository.Save())
            {
                return(StatusCode(500, "An error occured while processing your request"));
            }

            var donationCreated = _mapper.Map <DonationDto>(donationEntity);

            return(CreatedAtAction("Post", new { id = donationEntity.ID }, donationCreated));
        }
Exemplo n.º 6
0
        public int Create(CreateDonationDTO createDonationDTO)
        {
            DateTime createdAt      = DateTime.UtcNow;
            var      donor          = _donorRepository.GetById(int.Parse(createDonationDTO.DonorId));
            var      bloodcenter    = _bloodcenterRepository.GetById(int.Parse(createDonationDTO.BloodCenterId));
            var      parsedSchedule = DateTime.Parse(createDonationDTO.Schedule);

            Donation donation = new Donation(int.Parse(createDonationDTO.DonorId),
                                             int.Parse(createDonationDTO.BloodCenterId),
                                             createDonationDTO.Status,
                                             parsedSchedule,
                                             createdAt
                                             );

            return(_donationRepository.Create(donation));
        }
Exemplo n.º 7
0
 public Donation_Details Create(Donation_Details obj)
 {
     return(_IDonationRepo.Create(obj));
 }
Exemplo n.º 8
0
        public async System.Threading.Tasks.Task <ActionResult> MakeADonation(DonationViewModels model)
        {
            //Setting donation details from formData
            //TODO:
            //Save to database
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            List <HttpPostedFile> files = new List <HttpPostedFile>();

            foreach (var f in Request.Files)
            {
                files.Add(f as HttpPostedFile);
            }

            try
            {
                var HeaderImagesJson    = Request.Params["headerImages"];
                var donationDetailsJson = Request.Params["details"];

                //Deserialization
                var           donationImages  = JsonConvert.DeserializeObject <List <FileViewModel> >(HeaderImagesJson);
                var           donationDetails = JsonConvert.DeserializeObject <List <DonationDetailsViewModels> >(donationDetailsJson);
                List <string> filesAdded      = new List <string>();
                model.DonationDetails = donationDetails;
                var imageService = new ImageService(log);
                ViewBag.StatusMessage = "";


                //Amount validation if money is on
                if (model.IsMoney && model.Amount <= 0)
                {
                    ViewBag.StatusMessage = Resources.InvalidAmount;
                    return(View(model));
                }

                filesAdded = new List <string>();
                foreach (var line in model.DonationDetails)
                {
                    foreach (var file in line.MultiFileData)
                    {
                        //check if the image already exist.
                        var fileExist = filesAdded.Any(x => x == file.Name);
                        if (!fileExist)
                        {
                            //upload image to azure
                            var fileToUpload = file.GetFile(Request.Files);
                            if (fileToUpload != null)
                            {
                                var imageUrl = await imageService.CreateUploadedImageAsync(fileToUpload, Guid.NewGuid().ToString(), true, 500, 500);

                                line.Images.Add(new ImageViewModel()
                                {
                                    Item = line, ImageUrl = imageUrl
                                });
                                filesAdded.Add(file.Name);
                            }
                        }
                    }
                }

                //Class Injection
                CurrentUser = userRepository.GetByUserName(User.Identity.Name);
                var donation = new Donation {
                    Amount         = model.Amount,
                    CreatedBy      = CurrentUser,
                    CreatedOn      = DateTime.Now,
                    DonatedOn      = DateTime.Now,
                    Description    = model.Description,
                    DonationStatus = (Core.Entities.DonationStatus)model.DonationStatus,
                    ExpireOn       = model.ExpireOn,
                    Title          = model.Title,
                    ModifiedOn     = null
                };


                //Donation Images
                filesAdded = new List <string>();
                foreach (var fileWrapper in model.HeaderMultiFileData)
                {
                    //check if the image already exist.
                    var fileExist = filesAdded.Any(x => x == fileWrapper.FileName);
                    if (!fileExist)
                    {
                        var file     = fileWrapper as HttpPostedFileBase;
                        var imageUrl = await imageService.CreateUploadedImageAsync(file, Guid.NewGuid().ToString(), true, 500, 500);

                        donation.AddImage(new DonationImage()
                        {
                            Donation = donation, ImageUrl = imageUrl, CreatedBy = CurrentUser, CreatedOn = DateTime.Now, ModifiedOn = null
                        });
                        filesAdded.Add(fileWrapper.FileName);
                    }
                }

                if (model.DonationDetails != null && model.DonationDetails.Count() > 0)
                {
                    donation.DonationDetails = new List <DonationDetails>();
                }
                else
                {
                    donation.DonationDetails = null;
                }

                if (!model.IsMoney)
                {
                    foreach (var item in model.DonationDetails)
                    {
                        var itemLine = new DonationDetails
                        {
                            CreatedBy      = CurrentUser,
                            Donation       = donation,
                            CreatedOn      = DateTime.Now,
                            ItemName       = item.ItemName,
                            ItemType       = (Core.Entities.DonationType)item.ItemType,
                            Line           = item.Index,
                            DonationStatus = (Core.Entities.DonationStatus)item.DonationStatus,
                            ModifiedOn     = null
                        };

                        foreach (var image in item.Images)
                        {
                            itemLine.Images.Add(
                                new DonationDetailsImage
                            {
                                CreatedBy  = CurrentUser,
                                Item       = itemLine,
                                ImageUrl   = image.ImageUrl,
                                CreatedOn  = DateTime.Now,
                                ModifiedOn = null
                            });
                        }

                        donation.DonationDetails.Add(itemLine);
                    }
                }

                //save to database
                donationRepository.Create(donation);
                //Success
                return(Json(new { result = "Redirect", url = Url.Action("Index", "Donations", new { Message = DonationMessageId.CrateDonationSuccess }) }));
            }
            catch (System.Exception ex)
            {
                ViewBag.StatusMessage = ex.Message;
            }

            return(Json(new { result = "Error", Message = ViewBag.StatusMessage }));;
        }