Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.78 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Web.Mvc;
  4. using ShawCustomerSalesManager.Helpers;
  5. using ShawCustomerSalesManager.Models;
  6. using System.Collections.Generic;
  7.  
  8. namespace ShawCustomerSalesManager.Controllers
  9. {
  10. public class CustomerController : Controller
  11. {
  12. readonly ShawCommercialWebUsersDataClassesDataContext userContext = new ShawCommercialWebUsersDataClassesDataContext(StaticUtils.GetWebUsersConnString());
  13. //
  14. // GET: /User/
  15.  
  16. [Authorize]
  17. public ActionResult Index()
  18. {
  19. var db = userContext;
  20. var userObj = (from userTblObj in userContext.Users
  21. where userTblObj.SOAStatusID == 3
  22. select userTblObj);
  23.  
  24. var SOAStatusObj = from soaStatusTblObj in userContext.SOAStatus
  25. select soaStatusTblObj;
  26. ViewData["Statuses"] = SOAStatusObj;
  27.  
  28. return View(userObj);
  29. }
  30.  
  31. //[Authorize]
  32. //to be depricated
  33. //public ActionResult ShowPendingCustomersByTerritoryID(int id)
  34. //{
  35. // var userObj = from userTblObj in userContext.Users
  36. // where userTblObj.TerritoryID == id && userTblObj.SOAStatusID == 3
  37. // select userTblObj;
  38.  
  39. // var SOAStatusObj = from soaStatusTblObj in userContext.SOAStatus
  40. // select soaStatusTblObj;
  41. // ViewData["Statuses"] = SOAStatusObj;
  42.  
  43. // return View("ShowCustomersByTerritoryID", userObj);
  44. //}
  45.  
  46. public ActionResult ShowCustomersByTerritoryID(int id, string status)
  47. {
  48. var territory = Territory.Find(id);
  49.  
  50. List<User> users;
  51.  
  52. if (status.ToLower().Equals("pending"))
  53. users = territory.PendingUsers;
  54. else
  55. users = territory.Users;
  56.  
  57. var SOAStatusObj = from soaStatusTblObj in userContext.SOAStatus
  58. select soaStatusTblObj;
  59. ViewData["Statuses"] = SOAStatusObj;
  60.  
  61. return View("ShowCustomersByTerritoryID", users);
  62. }
  63.  
  64. public ActionResult Show(string id)
  65. {
  66. id = SymCryptography.Decrypt(id, Config.EncryptionKey);
  67.  
  68. int userId;
  69. int.TryParse(id, out userId);
  70.  
  71. var user = Models.User.Find(userId);
  72.  
  73. var SOAStatusObj = from soaStatusTblObj in userContext.SOAStatus
  74. select soaStatusTblObj;
  75. ViewData["Statuses"] = SOAStatusObj;
  76.  
  77. return View("Show", user);
  78. }
  79.  
  80. public ActionResult DenyUser(string UserID, string key)
  81. {
  82.  
  83. try
  84. {
  85. int userIDInt;
  86. var soaStatusIDInt = Config.STATUS_DECLINED;
  87. int.TryParse(UserID, out userIDInt);
  88.  
  89. var user = userContext.Users.First(p => p.Id == userIDInt);
  90.  
  91. //validate cryption with the en in front
  92. var cryptic = new SymCryptography();
  93. cryptic.Key = userIDInt.ToString();
  94.  
  95. if (cryptic.Decrypt(key) == user.Email)
  96. {
  97. user.SOAStatusID = soaStatusIDInt;
  98. userContext.SubmitChanges();
  99.  
  100. return View("UserDenied");
  101. }
  102. return View("InvalidUrl");
  103. }
  104. catch (Exception e)
  105. {
  106. return View(e.Message);
  107. }
  108. }
  109.  
  110. public ActionResult UpdateIndividualSOAStatus(string UserID, string NewSOAStatusID)
  111. {
  112. try
  113. {
  114. SaveSOAStatus(UserID, NewSOAStatusID);
  115. TempData["Message"] = "Customer's approval status has been updated";
  116. }
  117. catch (Exception e)
  118. {
  119. TempData["Message"] = e.Message;
  120. }
  121. return RedirectToAction("Show", new { id = SymCryptography.Encrypt(UserID, Config.EncryptionKey) });
  122. }
  123.  
  124. [Authorize]
  125. public ActionResult UpdateSOAStatus(string UserID, string NewSOAStatusID)
  126. {
  127. try
  128. {
  129. var soaStatusIDInt = SaveSOAStatus(UserID, NewSOAStatusID);
  130.  
  131. if (soaStatusIDInt == Config.STATUS_DECLINED)
  132. { return View("UserDenied"); }
  133. return RedirectToAction("index");
  134. }
  135. catch(Exception e)
  136. {
  137. return View(e.Message);
  138. }
  139. }
  140.  
  141.  
  142. //takes in StatusID
  143. [Authorize]
  144. public ActionResult ShowSOAStatus()
  145. {
  146.  
  147. var SOAStatusObj = from soaStatusTblObj in userContext.SOAStatus
  148. select soaStatusTblObj;
  149.  
  150. ViewData["Statuses"] = SOAStatusObj;
  151.  
  152. return View();
  153. }
  154.  
  155.  
  156. //
  157. // GET: /User/Details/5
  158. [Authorize]
  159. public ActionResult Details(int id)
  160. {
  161. return View();
  162. }
  163.  
  164. //
  165. // GET: /User/Create
  166. [Authorize]
  167. public ActionResult Create()
  168. {
  169. return View();
  170. }
  171.  
  172. //
  173. // POST: /User/Create
  174. [Authorize]
  175. [AcceptVerbs(HttpVerbs.Post)]
  176. public ActionResult Create(FormCollection collection)
  177. {
  178. try
  179. {
  180. // TODO: Add insert logic here
  181.  
  182. return RedirectToAction("Index");
  183. }
  184. catch
  185. {
  186. return View();
  187. }
  188. }
  189.  
  190. //
  191. // GET: /User/Edit/5
  192. [Authorize]
  193. public ActionResult Edit(int id)
  194. {
  195. return View();
  196. }
  197.  
  198. //
  199. // POST: /User/Edit/5
  200. [Authorize]
  201. [AcceptVerbs(HttpVerbs.Post)]
  202. public ActionResult Edit(int id, FormCollection collection)
  203. {
  204. try
  205. {
  206. // TODO: Add update logic here
  207.  
  208. return RedirectToAction("Index");
  209. }
  210. catch
  211. {
  212. return View();
  213. }
  214. }
  215.  
  216.  
  217. private int SaveSOAStatus(string UserID, string NewSOAStatusID)
  218. {
  219. int userIDInt;
  220. int soaStatusIDInt;
  221. int.TryParse(UserID, out userIDInt);
  222. int.TryParse(NewSOAStatusID, out soaStatusIDInt);
  223.  
  224. var user = userContext.Users.First(p => p.Id == userIDInt);
  225.  
  226. user.SOAStatusID = soaStatusIDInt;
  227. userContext.SubmitChanges();
  228. return soaStatusIDInt;
  229. }
  230. }
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement