/// <summary> /// Get about page with different variables /// </summary> /// <returns>Returns about page</returns> public ActionResult About() { ViewBag.Message = "Om oss"; var AboutList = _context.About.ToList(); var About = new DbTables.Info(); if (AboutList.Any()) { About = AboutList.First(); } var TwitterList = _context.Twitter.ToList(); var Twitter = new DbTables.Twitter(); if (TwitterList.Any()) { Twitter = TwitterList.First(); } var FacebookList = _context.Facebook.ToList(); var Facebook = new DbTables.Facebook(); if (FacebookList.Any()) { Facebook = FacebookList.First(); } //var style = "background:url(/File/Background?id="+") no-repeat center center fixed"; var background = new DbTables.BackgroundImage(); var backgroundList = _context.BackgroundImage.ToList(); if (backgroundList.Any()) { background = backgroundList.First(); if (background.Enabeled) { ViewBag.Style = "background:url('/File/Background?id=" + background.Image.FileId + "') no-repeat center center fixed;-webkit-background-size: cover;-moz-background-size: cover;-o-background-size: cover;background-size: cove;overflow-x: hidden;"; ViewBag.BackGround = "background-color:transparent;"; } } var AboutModel = new AboutModel { About = About, Facebook = Facebook, Twitter = Twitter }; return(View(AboutModel)); }
/// <summary> /// Edit values /// </summary> /// <param name="model">Model values to change</param> /// <returns>view with updated info and success/failure message</returns> public ActionResult EditFacebook(DbTables.Facebook model) { if (ModelState.IsValid) { try { var Facebook = new DbTables.Facebook(); var FacebookList = _context.Facebook.ToList(); if (FacebookList.Any()) { Facebook = FacebookList.First(); Facebook.Url = model.Url; } else { Facebook.Url = model.Url; Facebook.Enabeled = true; _context.Facebook.Add(Facebook); } _context.SaveChanges(); ViewBag.Success = "Facebook variabler ble sukessfult oppdatert"; return(PartialView("_FacebookPartial", _context.Facebook.First())); } catch (EntityException ex) { ViewBag.Error = "Error:" + ex.Message; return(PartialView("_FacebookPartial", _context.Facebook.First())); } } var FacebookError = new DbTables.Facebook(); var FacebookListError = _context.Facebook.ToList(); if (FacebookListError.Any()) { FacebookError = FacebookListError.First(); } var messages = string.Join("\r\n\r\n", ModelState.Values //validation failed, return errors .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage)); ViewBag.Error = "Ugyldige verdier: " + messages; return(PartialView("_FacebookPartial", FacebookError)); }
// GET: Admin/Various /// <summary> /// Index view of various, check if various database elements are actually added and then add these to the model if /// they exist /// </summary> /// <returns>Various index view</returns> public ActionResult Index() { var carouselObj = new DbTables.Carousel(); var GoogleCap = new DbTables.GoogleCaptchaAPI(); var GoogleCapList = _context.GoogleCaptchaAPI.ToList(); if (GoogleCapList.Any()) { GoogleCap = GoogleCapList.First(); } var SendG = new DbTables.SendGridAPI(); var SendgridList = _context.SendGridAPI.ToList(); if (SendgridList.Any()) { SendG = SendgridList.First(); } var Stripe = new DbTables.StripeAPI(); var StripeList = _context.StripeAPI.ToList(); if (StripeList.Any()) { Stripe = StripeList.First(); } var Facebook = new DbTables.Facebook(); var FacebookList = _context.Facebook.ToList(); if (FacebookList.Any()) { Facebook = FacebookList.First(); } var Twitter = new DbTables.Twitter(); var TwitterList = _context.Twitter.ToList(); if (TwitterList.Any()) { Twitter = TwitterList.First(); } var Disqus = new DbTables.Disqus(); var DisqusList = _context.Disqus.ToList(); if (DisqusList.Any()) { Disqus = DisqusList.First(); } var About = new DbTables.Info(); var AboutList = _context.About.ToList(); if (AboutList.Any()) { About = AboutList.First(); } var carousel = _context.Carousel.ToList(); if (carousel.Any()) { carouselObj = carousel.First(); } var Terms = new DbTables.TermsOfUse(); var TermsList = _context.TermsOfUse.ToList(); if (TermsList.Any()) { Terms = TermsList.First(); } var Background = new DbTables.BackgroundImage(); var BackgroundList = _context.BackgroundImage.ToList(); if (BackgroundList.Any()) { Background = BackgroundList.First(); } var model = new VariousModel { GoogleCaptchaAPI = GoogleCap, SendGridAPI = SendG, Terms = Terms, Carousel = carouselObj, About = About, StripeAPI = Stripe, Twitter = Twitter, Facebook = Facebook, Background = Background, Disqus = Disqus }; return(View(model)); }
/// <summary> /// Handles subscription payments. Creates user and subscribes to plan /// </summary> /// <returns>reciept</returns> public ActionResult HandleSubPayment() { var subId = Request.Form["subId"]; var anon = Request.Form["anon"]; var user = Request.Form["user"]; var token = Request.Form["token"]; var email = Request.Form["email"]; var phone = Request.Form["phone"]; var birthnumber = Request.Form["birthnumber"]; var name = Request.Form["name"]; var description = Request.Form["description"]; var recieptemail = ""; //email to send reciept var recieptname = ""; //name on reciept var client = new WebClient(); var data = new NameValueCollection(); data["source"] = token; //the payment token with user's credidentials if (user == "true") { var manager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(_context)); var currentUser = manager.FindById(User.Identity.GetUserId()); recieptemail = currentUser.Email; recieptname = currentUser.Fname + " " + currentUser.Lname; data["email"] = currentUser.Email; data["description"] = "Bruker " + email + " i databasen: " + description; //set description of donation } else if ((anon == "true") && !string.IsNullOrEmpty(description)) { data["description"] = description; } else { if (!string.IsNullOrEmpty(email)) { data["email"] = email; recieptemail = email; } recieptname = name; data["description"] = "Telefon: " + phone + " - Navn: " + name + " - Fødselsnummer: " + birthnumber + " - Beskrivelse: " + description; } client.UseDefaultCredentials = true; //use default credidentials for API request var stripeList = _context.StripeAPI.ToList(); //check if stripe actually exists in the database byte[] response; if (!stripeList.Any()) { return (Json( new { Error = "Stripe er ikke konfigurert for applikasjonen.", Succsess = "false", striperesponse = "false" })); //no stripe in database, return error } if (!stripeList.First().Enabeled) { return (Json( new { Error = "Stripe er avslått for applikasjonen.", Succsess = "false", striperesponse = "false" })); //stripe disabeled } client.Credentials = new NetworkCredential(_context.StripeAPI.ToList().First().Secret, ""); try { response = client.UploadValues("https://api.stripe.com/v1/customers", "POST", data); // upload values and get response } catch (WebException exception) //exepction happen when poisting to API { string responseString; using (var reader = new StreamReader(exception.Response.GetResponseStream())) //read the errorstring { responseString = reader.ReadToEnd(); } return(Json(new { Error = responseString, Success = "false", striperesponse = "true" })); // return responsestring as error message } //if we get here customer was succsessfully created var json_serializer = new JavaScriptSerializer(); var JsonDict = (IDictionary <string, object>)json_serializer.DeserializeObject(client.Encoding.GetString(response)); //deseroalize the response var customer = JsonDict["id"].ToString(); //get id of customer returned by the API data = new NameValueCollection(); //now create a collection for the plan and subscribe data["plan"] = subId; data["customer"] = customer; try { response = client.UploadValues("https://api.stripe.com/v1/subscriptions", "POST", data); // upload values and get response } catch (WebException exception) //exepction happen when poisting to API { string responseString; using (var reader = new StreamReader(exception.Response.GetResponseStream())) //read the errorstring { responseString = reader.ReadToEnd(); } return(Json(new { Error = responseString, Success = "false", striperesponse = "true" })); // return responsestring as error message } //customer successfully subscribed to plan JsonDict = (IDictionary <string, object>)json_serializer.DeserializeObject(client.Encoding.GetString(response)); //deseroalize the response var subscriptionId = JsonDict["id"].ToString(); Response.StatusCode = 200; var sub = _context.Subscriptions.Find(int.Parse(subId)); if (!string.IsNullOrEmpty(recieptemail)) //send reciept email if reciept email is given { var subject = "Kvitering på donasjon"; var message = "Takk for din støtte! \n Du har started et abonement med id " + subId + " for " + sub.Amount + " kroner i måneden til Butterfly Friends. \n" + "Ditt referansenummer er " + subscriptionId + ". \n\n" + "Vennlig hilsen,\nButterfly Friends."; var messageHTML = "<p>Takk for din støtte! <br> Du har startet et abonement med id " + subId + " for " + sub.Amount + " kroner i måneden til Butterfly Friends. <br>" + "Ditt referansenummer er: " + subscriptionId + ". <br><br>" + "Vennlig hilsen,<br>Butterfly Friends.</p>"; if (!SendEmail(message, messageHTML, subject, recieptemail, recieptname)) { //returns true if sending of email was succsessful ViewBag.Error = "Emailkviteringen kunne ikke sendes, Sendgrid er ikke konfigurert."; } } ViewBag.Share = "https://www." + Request.Url.Host + "/Home/Index"; //share link for twitter ViewBag.ShareText = "Jeg donerer " + sub.Amount + " kr i måneden til Butterfly Friends!"; //share message var TwitterList = _context.Twitter.ToList(); //check if facebook and twitter exist var Twitter = new DbTables.Twitter(); if (TwitterList.Any()) { Twitter = TwitterList.First(); } var FacebookList = _context.Facebook.ToList(); var Facebook = new DbTables.Facebook(); if (FacebookList.Any()) { Facebook = FacebookList.First(); } var subReciept = new SubReciept { Amount = sub.Amount, Id = subId, referenceId = subscriptionId }; var model = new RecieptModel { Facebook = Facebook, Twitter = Twitter, SubReciept = subReciept }; return(PartialView("_RecieptPartial", model)); //return reciept view }
public ActionResult HandlePayment() { var amount = int.Parse(Request.Form["amount"]); var anon = Request.Form["anon"]; var user = Request.Form["user"]; var token = Request.Form["token"]; var email = Request.Form["email"]; var phone = Request.Form["phone"]; var city = Request.Form["city"]; var streetadress = Request.Form["streetadress"]; var postcode = Request.Form["postcode"]; var birthnumber = Request.Form["birthnumber"]; var name = Request.Form["name"]; var description = Request.Form["description"]; var recieptemail = ""; var recieptname = ""; var donation = new DbTables.Donations(); if (anon == "true") //payment is anonymous { donation = new DbTables.Donations { Amount = amount, Description = description, anonymous = true }; } else if ((user == "true") && (User.Identity.GetUserId() != null)) //connet donation to user as long as there is actually a logged in user { var manager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(_context)); var currentUser = manager.FindById(User.Identity.GetUserId()); donation = new DbTables.Donations { Amount = amount, Description = description, anonymous = false, User = currentUser }; recieptname = currentUser.Fname + " " + currentUser.Lname; recieptemail = currentUser.Email; } else { donation = new DbTables.Donations //information has been given { Amount = amount, Email = email, Phone = phone, City = city, StreetAdress = streetadress, ZipCode = postcode, BirthNumber = birthnumber, Name = name, Description = description, anonymous = false }; recieptemail = email; recieptname = name; } _context.Donations.Add(donation); _context.SaveChanges(); // Process payment. var client = new WebClient(); var data = new NameValueCollection(); data["amount"] = (amount * 100).ToString(CultureInfo.InvariantCulture); // Stripe charges are øre-based in NOK, so 100x the price. data["currency"] = "nok"; data["source"] = token; //the payment token with user's credidentials data["description"] = "Donasjon " + donation.Id + ": " + description; //description of donation. if (!string.IsNullOrEmpty(email)) { data["receipt_email"] = email; } else if (user == "true") { data["receipt_email"] = donation.User.Email; } client.UseDefaultCredentials = true; //use default credidentials for API request var stripeList = _context.StripeAPI.ToList(); //check if stripe actually exists in the database byte[] response; if (!stripeList.Any()) { return (Json( new { Error = "Stripe er ikke konfigurert for applikasjonen.", Succsess = "false", striperesponse = "false" })); //no stripe in database, return error } if (!stripeList.First().Enabeled) { return (Json( new { Error = "Stripe er avslått for applikasjonen.", Succsess = "false", striperesponse = "false" })); //stripe disabeled } client.Credentials = new NetworkCredential(_context.StripeAPI.ToList().First().Secret, ""); try { response = client.UploadValues("https://api.stripe.com/v1/charges", "POST", data); // upload values and get response } catch (WebException exception) //exepction happen when poisting to API { string responseString; using (var reader = new StreamReader(exception.Response.GetResponseStream())) //read the errorstring { responseString = reader.ReadToEnd(); } return(Json(new { Error = responseString, Success = "false", striperesponse = "true" })); // return responsestring as error message } /*var json_serializer = new JavaScriptSerializer(); * var JsonDict = (IDictionary<string, object>)json_serializer.DeserializeObject(client.Encoding.GetString(response));*/ //These lines parses the respone, which is at the moment not used for anything // If we got this far, there were no errors, and we set the order to paid, and save. Response.StatusCode = 200; donation.isPaid = true; //change element to paid _context.SaveChanges(); //save db if (!string.IsNullOrEmpty(recieptemail)) //send reciept email if reciept email is given { var subject = "Kvitering på donasjon"; var message = "Takk for din støtte! \n Du har donert " + amount + " kroner til Butterfly Friends. \n" + "Ditt referansenummer er " + donation.Id + ". \n\n" + "Vennlig hilsen,\nButterfly Friends."; var messageHTML = "<p>Takk for din støtte! <br> Du har donert " + amount + " kroner til Butterfly Friends. <br>" + "Ditt referansenummer er " + donation.Id + ". <br><br>" + "Vennlig hilsen,<br>Butterfly Friends.</p>"; if (!SendEmail(message, messageHTML, subject, recieptemail, recieptname)) { //returns true if sending of email was succsessful ViewBag.Error = "Emailkviteringen kunne ikke sendes, Sendgrid er ikke konfigurert."; } } ViewBag.Share = "https://www." + Request.Url.Host + "/Home/Index"; //share link for twitter ViewBag.ShareText = "Jeg har donert " + amount + " kr. til Butterfly Friends!"; //share message var TwitterList = _context.Twitter.ToList(); //check if facebook and twitter exist var Twitter = new DbTables.Twitter(); if (TwitterList.Any()) { Twitter = TwitterList.First(); } var FacebookList = _context.Facebook.ToList(); var Facebook = new DbTables.Facebook(); if (FacebookList.Any()) { Facebook = FacebookList.First(); } var model = new RecieptModel { Facebook = Facebook, Twitter = Twitter, Donation = donation }; return(PartialView("_RecieptPartial", model)); //return reciept view }