Advertisement
Guest User

Controller

a guest
Jul 26th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using System.Web;
  8. using System.Web.Hosting;
  9. using System.Web.Mvc;
  10. using thePure5.Models;
  11.  
  12. namespace thePure5.Controllers
  13. {
  14. public class OrderNowController : Controller
  15. {
  16. //// GET: OrderNow
  17. //public ActionResult Index()
  18. //{
  19. // return View();
  20. //}
  21.  
  22. public ActionResult OrderNow()
  23. {
  24. return View();
  25. }
  26.  
  27. public static async Task<string> OrderTemplate(string template)
  28. {
  29. var templateFilePath = HostingEnvironment.MapPath("~/Content/orderTemplate/") + template + ".cshtml";
  30. StreamReader objstreamrederfile = new StreamReader(templateFilePath);
  31. var body = await objstreamrederfile.ReadToEndAsync();
  32. objstreamrederfile.Close();
  33. return body;
  34. }
  35.  
  36. [HttpPost]
  37. [AllowAnonymous]
  38. public async Task<ActionResult> OrderNow(OrderNowViewModel model)
  39. {
  40. if (ModelState.IsValid)
  41. {
  42. var message = await OrderTemplate("orderNowTemplate");
  43. message = message.Replace("@ViewBag.Name", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.Name));
  44.  
  45. message = message.Replace("@ViewBag.Company", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.Company));
  46.  
  47. message = message.Replace("@ViewBag.Company", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.Adress));
  48.  
  49. message = message.Replace("@ViewBag.Email", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.YourEmail));
  50.  
  51. message = message.Replace("@ViewBag.YourPhone", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.YourPhone));
  52.  
  53. message = message.Replace("@ViewBag.Type", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.Type));
  54.  
  55. message = message.Replace("@ViewBag.MonthlyVolume", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.MonthlyVolume));
  56.  
  57. message = message.Replace("@ViewBag.Quantity", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.Quantity));
  58.  
  59. message = message.Replace("@ViewBag.YourMsg", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.YourMsg));
  60. await OrderServices.OrderNowAsync(model.YourEmail, "Hello! I want to order !", message);
  61. ModelState.Clear();
  62. return View("OrderSent");
  63. }
  64.  
  65. return Redirect(Request.UrlReferrer.ToString());
  66.  
  67.  
  68. }
  69.  
  70.  
  71. public ActionResult OrderSent()
  72. {
  73.  
  74. return View();
  75.  
  76.  
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement