public ActionResult SaveStatus(int statusId, int?requestId, int requestorId) { string msg; if (Application.LoggedManagerId != null) { if (requestId != null) { var mgrId = (int)Application.LoggedManagerId; var reqId = (int)requestId; ViewData["Status"] = statusId; try { RequestsRepository.SaveRequest(requestorId, mgrId, statusId, reqId); return(Json(new { success = true, message = "Status saved for request Id " + reqId + " successfully!" })); } catch (Exception exc) { msg = exc.Message; BaseRepository.OimsDataContext.ClearChanges(); // Roll back all changes Logger.LogError(exc, "Error while saving status from Manager zone"); } } else { msg = Common.ErrorMsgReqNotFound; } } else { msg = Common.ErrorMsgForSession; } return(Json(new { success = false, message = msg })); }
public ActionResult SaveStatus(int statusId, int?requestId, int requestorId) { string msg; if (Application.LoggedSupervisorId != null) { if (requestId != null) { if (!statusId.Equals(1) || !statusId.Equals(6)) { var supId = (int)Application.LoggedSupervisorId; var reqId = (int)requestId; ViewData["Status"] = statusId; try { RequestsRepository.SaveRequest(requestorId, supId, statusId, reqId); try { #region Send email to Manager var sIdForEmail = Application.GetStatusId("SIdEmail"); if (!statusId.Equals(sIdForEmail)) { return(Json(new { success = true, message = "Request with Request Id: " + reqId + " saved successfully!" })); } // RoleId 1 stands for Manager var user = UserRepository.Users.FirstOrDefault(u => u.RoleId.Equals(1)); if (user != null) { Application.SendEmail(user.FirstName, user.Email, reqId); } #endregion } catch (Exception exc) { Logger.LogError(exc, "Error while sending email from Supervisor zone"); } return(Json(new { success = true, message = "Status saved for request Id " + reqId + " successfully!" })); } catch (Exception exc) { msg = exc.Message; BaseRepository.OimsDataContext.ClearChanges(); // Roll back all changes Logger.LogError(exc, "Error while saving status for request from Supervisor zone"); } } else { msg = "Supervisor can set two statuses 'Manager approval pending' or 'Closed' only."; } } else { msg = Common.ErrorMsgReqNotFound; } } else { msg = Common.ErrorMsgForSession; } return(Json(new { success = false, message = msg })); }