public ActionResult Create(DonationInput model) { if(ModelState.IsValid) { var donation = Donation.CreatFromInput(model); RavenSession.Store(donation); return RedirectToAction("Index"); } return View(model); }
public ActionResult Index(DonationInput attempt) { if (ModelState.IsValid) { Donation donation = Donation.CreatFromInput(attempt); RavenSession.Store(donation); RavenSession.SaveChanges(); Session[DonationIDKey] = donation.Id; string paypalUrl = GetPaypalUrl(attempt); return Redirect(paypalUrl); } return View(attempt); }
public static ValidationResult FinalCheck(DonationInput input, ValidationContext validationContext) { if (input.Amount.HasValue == false && input.OtherAmount.HasValue == false) return new ValidationResult("Please enter amount."); return ValidationResult.Success; }
public static Donation CreatFromInput(DonationInput attempt) { return new Donation { Name = attempt.Name, Amount = attempt.Amount == null ? attempt.OtherAmount.Value : attempt.Amount.Value, Message = attempt.Message, Email = attempt.Email, DontShowName = attempt.DontShowName, Date = DateTimeOffset.Now, CampaignName = attempt.Campaign ?? "General" }; }
private string GetPaypalUrl(DonationInput attempt) { UriBuilder builder = new UriBuilder("https://www.paypal.com/cgi-bin/webscr"); NameValueCollection query = new NameValueCollection(); query["cmd"] = "_donations"; query["business"] = "*****@*****.**"; query["lc"] = "GB"; query["item_name"] = "Support Sasha"; query["item_number"] = attempt.Campaign; query["currency_code"] = "GBP"; query["bn"] = "PP-DonationsBF:btn_donateCC_LG.gif:NonHosted"; query["amount"] = attempt.Amount.ToString(); query["return"] = WebHelpers.ResolveServerUrl("/donations/thankyou"); builder.Query = ToQueryString(query); return builder.Uri.ToString(); }