Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Web.Mvc;
- using ShawCustomerSalesManager.Helpers;
- using ShawCustomerSalesManager.Models;
- using System.Collections.Generic;
- namespace ShawCustomerSalesManager.Controllers
- {
- public class CustomerController : Controller
- {
- readonly ShawCommercialWebUsersDataClassesDataContext userContext = new ShawCommercialWebUsersDataClassesDataContext(StaticUtils.GetWebUsersConnString());
- //
- // GET: /User/
- [Authorize]
- public ActionResult Index()
- {
- var db = userContext;
- var userObj = (from userTblObj in userContext.Users
- where userTblObj.SOAStatusID == 3
- select userTblObj);
- var SOAStatusObj = from soaStatusTblObj in userContext.SOAStatus
- select soaStatusTblObj;
- ViewData["Statuses"] = SOAStatusObj;
- return View(userObj);
- }
- //[Authorize]
- //to be depricated
- //public ActionResult ShowPendingCustomersByTerritoryID(int id)
- //{
- // var userObj = from userTblObj in userContext.Users
- // where userTblObj.TerritoryID == id && userTblObj.SOAStatusID == 3
- // select userTblObj;
- // var SOAStatusObj = from soaStatusTblObj in userContext.SOAStatus
- // select soaStatusTblObj;
- // ViewData["Statuses"] = SOAStatusObj;
- // return View("ShowCustomersByTerritoryID", userObj);
- //}
- public ActionResult ShowCustomersByTerritoryID(int id, string status)
- {
- var territory = Territory.Find(id);
- List<User> users;
- if (status.ToLower().Equals("pending"))
- users = territory.PendingUsers;
- else
- users = territory.Users;
- var SOAStatusObj = from soaStatusTblObj in userContext.SOAStatus
- select soaStatusTblObj;
- ViewData["Statuses"] = SOAStatusObj;
- return View("ShowCustomersByTerritoryID", users);
- }
- public ActionResult Show(string id)
- {
- id = SymCryptography.Decrypt(id, Config.EncryptionKey);
- int userId;
- int.TryParse(id, out userId);
- var user = Models.User.Find(userId);
- var SOAStatusObj = from soaStatusTblObj in userContext.SOAStatus
- select soaStatusTblObj;
- ViewData["Statuses"] = SOAStatusObj;
- return View("Show", user);
- }
- public ActionResult DenyUser(string UserID, string key)
- {
- try
- {
- int userIDInt;
- var soaStatusIDInt = Config.STATUS_DECLINED;
- int.TryParse(UserID, out userIDInt);
- var user = userContext.Users.First(p => p.Id == userIDInt);
- //validate cryption with the en in front
- var cryptic = new SymCryptography();
- cryptic.Key = userIDInt.ToString();
- if (cryptic.Decrypt(key) == user.Email)
- {
- user.SOAStatusID = soaStatusIDInt;
- userContext.SubmitChanges();
- return View("UserDenied");
- }
- return View("InvalidUrl");
- }
- catch (Exception e)
- {
- return View(e.Message);
- }
- }
- public ActionResult UpdateIndividualSOAStatus(string UserID, string NewSOAStatusID)
- {
- try
- {
- SaveSOAStatus(UserID, NewSOAStatusID);
- TempData["Message"] = "Customer's approval status has been updated";
- }
- catch (Exception e)
- {
- TempData["Message"] = e.Message;
- }
- return RedirectToAction("Show", new { id = SymCryptography.Encrypt(UserID, Config.EncryptionKey) });
- }
- [Authorize]
- public ActionResult UpdateSOAStatus(string UserID, string NewSOAStatusID)
- {
- try
- {
- var soaStatusIDInt = SaveSOAStatus(UserID, NewSOAStatusID);
- if (soaStatusIDInt == Config.STATUS_DECLINED)
- { return View("UserDenied"); }
- return RedirectToAction("index");
- }
- catch(Exception e)
- {
- return View(e.Message);
- }
- }
- //takes in StatusID
- [Authorize]
- public ActionResult ShowSOAStatus()
- {
- var SOAStatusObj = from soaStatusTblObj in userContext.SOAStatus
- select soaStatusTblObj;
- ViewData["Statuses"] = SOAStatusObj;
- return View();
- }
- //
- // GET: /User/Details/5
- [Authorize]
- public ActionResult Details(int id)
- {
- return View();
- }
- //
- // GET: /User/Create
- [Authorize]
- public ActionResult Create()
- {
- return View();
- }
- //
- // POST: /User/Create
- [Authorize]
- [AcceptVerbs(HttpVerbs.Post)]
- public ActionResult Create(FormCollection collection)
- {
- try
- {
- // TODO: Add insert logic here
- return RedirectToAction("Index");
- }
- catch
- {
- return View();
- }
- }
- //
- // GET: /User/Edit/5
- [Authorize]
- public ActionResult Edit(int id)
- {
- return View();
- }
- //
- // POST: /User/Edit/5
- [Authorize]
- [AcceptVerbs(HttpVerbs.Post)]
- public ActionResult Edit(int id, FormCollection collection)
- {
- try
- {
- // TODO: Add update logic here
- return RedirectToAction("Index");
- }
- catch
- {
- return View();
- }
- }
- private int SaveSOAStatus(string UserID, string NewSOAStatusID)
- {
- int userIDInt;
- int soaStatusIDInt;
- int.TryParse(UserID, out userIDInt);
- int.TryParse(NewSOAStatusID, out soaStatusIDInt);
- var user = userContext.Users.First(p => p.Id == userIDInt);
- user.SOAStatusID = soaStatusIDInt;
- userContext.SubmitChanges();
- return soaStatusIDInt;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement