public ActionResult CreateRequest(RequestPO requestPO) { ActionResult response; //check if logged in if (Session["RoleID"] != null) { //if logged in, check the model state try { //check model if (ModelState.IsValid) { //if model is valid, get user information for username UserDO user = _UserDataAccess.ViewUserByID((int)Session["UserID"]); //map from view model to a DO RequestDO request = new RequestDO() { RequestText = requestPO.RequestText, Username = user.Username, Date = DateTime.Now.ToString(), }; //access database _RequestDataAccess.CreateRequest(request); //show confirmation screen response = RedirectToAction("RequestSubmitted", "Request"); } else { //if model is not valid, return to form response = View(requestPO); } } catch (Exception ex) { //log error _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); response = View(requestPO); } finally { } } else { //if not logged in, redirect to login page response = RedirectToAction("Login", "Account"); } return(response); }
public JsonResult AddStationeryRequest(List <RequestStationery> itemData) { if (itemData == null) { return(Json("Your item list is empty!", JsonRequestBehavior.AllowGet)); } // add itemid to array int listLength = itemData.Count; string[] itemid = new string[listLength]; for (int i = 0; i < listLength; i++) { itemid[i] = itemData[i].ItemId; } //////////////////////////////////////////// ///////////////get employee////////////// EmployeeDAO employeeDAO = new EmployeeDAO(); Employee emp = new Employee(); emp = employeeDAO.GetEmployeeByUsername(Session["username"].ToString()); int empId = emp.Id; string deptId = emp.DepartmentId; /////////////////////////////////////////// RequestDAO req = new RequestDAO(); List <RequestStationery> reqStationery = new List <RequestStationery>(); reqStationery = itemData; if (req.CreateRequest(empId, reqStationery)) { EmailDAO emailDAO = new EmailDAO(); string mgrEmail = emailDAO.EmailReviewStationeryRequest(empId); Email email = new Email(); string message = "Please check for new stationery Request. Do not reply this is system generated message.Thanks " + emp.Name; email.SendEmail(mgrEmail, "New Stationery Request", message); return(Json("Successfully Added", JsonRequestBehavior.AllowGet)); } else { return(Json("Something went wrong! Please try again later.", JsonRequestBehavior.AllowGet)); } }