public JsonResult CloseLeaveCancelationRequest(FormCollection formCollection) { string userComment = formCollection["userComment"]; string requestId = formCollection["requestId"]; try { UserProfile currentUser = (Session["UserProfileSession"] as UserProfile); if (currentUser == null || requestId == null || requestId.Trim() == "") { throw new Exception("Invalid request"); } if (userComment != null) { userComment = userComment.Trim(); } NueRequestActivityMaster nueRequestNewStatus = new DataAccess().getRequestStatus("close"); NueRequestActivityMaster nueRequestStatus = new DataAccess().getRequestStatus("completed"); var userAceess = currentUser.userAccess; List <NueRequestAceessLog> nueRequestAceessLogs = new DataAccess().getRequestAccessList(requestId); UserRequest userRequest = new DataAccess().getRequestDetailsByReqId(requestId); if (userRequest.OwnerId == currentUser.Id) { if (userRequest.NueRequestStatusId == nueRequestStatus.Id) { var dateCreated = DateTime.UtcNow; NueRequestMaster nueRequestMaster = new NueRequestMaster(); nueRequestMaster.Id = userRequest.NueRequestMasterId; nueRequestMaster.RequestStatus = nueRequestNewStatus.Id; nueRequestMaster.ModifiedOn = dateCreated; int newRequestTempInternId = new DataAccess().updateNeuRequestStatusLogs(nueRequestMaster); if (newRequestTempInternId != -1) { NueRequestActivityMaster nueRequestCmtActivityMaster = new DataAccess().getRequestActivityMasterId("Comment"); string appCmt = currentUser.FullName + " (" + currentUser.NTPLID + ") - close the request."; if (userComment != null && userComment.Trim() != "") { NueRequestActivity nueRequestActivity1 = new NueRequestActivity(); nueRequestActivity1.Payload = userComment; nueRequestActivity1.PayloadType = nueRequestCmtActivityMaster.Id; nueRequestActivity1.UserId = currentUser.Id; nueRequestActivity1.RequestId = userRequest.NueRequestMasterId; nueRequestActivity1.Request = userRequest.RequestId; nueRequestActivity1.AddedOn = dateCreated; nueRequestActivity1.ModifiedOn = dateCreated; new DataAccess().addRequestComment(nueRequestActivity1); } nueRequestCmtActivityMaster = new DataAccess().getRequestActivityMasterId("Close"); NueRequestActivity nueRequestActivity2 = new NueRequestActivity(); nueRequestActivity2.Payload = appCmt; nueRequestActivity2.PayloadType = nueRequestCmtActivityMaster.Id; nueRequestActivity2.UserId = currentUser.Id; nueRequestActivity2.RequestId = userRequest.NueRequestMasterId; nueRequestActivity2.Request = userRequest.RequestId; nueRequestActivity2.AddedOn = dateCreated; nueRequestActivity2.ModifiedOn = dateCreated; new DataAccess().addRequestComment(nueRequestActivity2); return(Json(new JsonResponse("Ok", "Request closed successfully."), JsonRequestBehavior.AllowGet)); } else { throw new Exception("An error occerd"); } } else { return(Json(new JsonResponse("Failed", "Invalid Operation, Request is not in approved state"), JsonRequestBehavior.AllowGet)); } } else { return(Json(new JsonResponse("Failed", "You are not authorised to close the request"), JsonRequestBehavior.AllowGet)); } } catch (Exception e) { return(Json(new JsonResponse("Failed", "An error occerd while updating data"), JsonRequestBehavior.AllowGet)); } }
public JsonResult SubApproveLeaveCancelationRequest(FormCollection formCollection) { string userComment = formCollection["userComment"]; string requestId = formCollection["requestId"]; try { UserProfile currentUser = (Session["UserProfileSession"] as UserProfile); if (currentUser == null || requestId == null || requestId.Trim() == "") { throw new Exception("Invalid request"); } if (userComment != null) { userComment = userComment.Trim(); } NueRequestActivityMaster nueRequestActivityMaster = new DataAccess().getRequestActivityMasterId("L1 Approval"); NueRequestActivityMaster nueRequestNewStatus = new DataAccess().getRequestStatus("In_Approval"); var userAceess = currentUser.userAccess; bool userAccess = false; int adminUsers = userAceess.Where(x => (x.AccessDesc == "Root_Admin" || x.AccessDesc == "Hcm_Admin" || x.AccessDesc == "Hcm_User")).Count(); UserRequest userRequest = new DataAccess().getRequestDetailsByReqId(requestId); List <NueRequestAceessLog> nueRequestAceessLogs = new DataAccess().getRequestAccessList(requestId); List <UserProfile> userProfiles = new DataAccess().getAllUserProfiles(); NeuLeaveCancelationModal neuLeaveCancelationModal = new DataAccess().getNeuLeaveCancelationDetails(requestId); if (userRequest == null) { throw new Exception("Invalid request"); } if (nueRequestAceessLogs.Where(x => x.UserId == currentUser.Id && x.OwnerId != currentUser.Id).Count() > 0) { userAccess = true; } if (userAccess) { var dateCreated = DateTime.UtcNow; NueRequestAceessLog nueRequestAceessLog = new NueRequestAceessLog(); nueRequestAceessLog.RequestId = userRequest.NueRequestMasterId; nueRequestAceessLog.UserId = currentUser.Id; nueRequestAceessLog.Completed = 1; nueRequestAceessLog.ModifiedOn = dateCreated; int updated = new DataAccess().updateNeuRequestAccessLogs(nueRequestAceessLog); if (updated != -1) { NueRequestMaster nueRequestMaster = new NueRequestMaster(); nueRequestMaster.Id = userRequest.NueRequestMasterId; nueRequestMaster.RequestStatus = nueRequestNewStatus.Id; nueRequestMaster.ModifiedOn = dateCreated; int newRequestTempInternId = new DataAccess().updateNeuRequestStatusLogs(nueRequestMaster); if (newRequestTempInternId != -1) { NueRequestActivityMaster nueRequestCmtActivityMaster = new DataAccess().getRequestActivityMasterId("Comment"); string appCmt = currentUser.FullName + " (" + currentUser.NTPLID + ") approved the request."; if (userComment != null && userComment.Trim() != "") { NueRequestActivity nueRequestActivity1 = new NueRequestActivity(); nueRequestActivity1.Payload = userComment; nueRequestActivity1.PayloadType = nueRequestCmtActivityMaster.Id; nueRequestActivity1.UserId = currentUser.Id; nueRequestActivity1.RequestId = userRequest.NueRequestMasterId; nueRequestActivity1.Request = userRequest.RequestId; nueRequestActivity1.AddedOn = dateCreated; nueRequestActivity1.ModifiedOn = dateCreated; new DataAccess().addRequestComment(nueRequestActivity1); } nueRequestCmtActivityMaster = new DataAccess().getRequestActivityMasterId("L1 Approval"); NueRequestActivity nueRequestActivity2 = new NueRequestActivity(); nueRequestActivity2.Payload = appCmt; nueRequestActivity2.PayloadType = nueRequestCmtActivityMaster.Id; nueRequestActivity2.UserId = currentUser.Id; nueRequestActivity2.RequestId = userRequest.NueRequestMasterId; nueRequestActivity2.Request = userRequest.RequestId; nueRequestActivity2.AddedOn = dateCreated; nueRequestActivity2.ModifiedOn = dateCreated; new DataAccess().addRequestComment(nueRequestActivity2); return(Json(new JsonResponse("Ok", "Request approved successfully."), JsonRequestBehavior.AllowGet)); } else { throw new Exception("An error occerd"); } } else { throw new Exception("An error occerd"); } } else { throw new Exception("Invalid opration"); } } catch (Exception e) { return(Json(new JsonResponse("Failed", "An error occerd while updating data"), JsonRequestBehavior.AllowGet)); } }
public ActionResult LeaveCancelation(LeaveCancelationUiRender leaveCancelationUiRender) { UserProfile currentUser = (Session["UserProfileSession"] as UserProfile); try { var dateCreated = DateTime.UtcNow; List <UserProfile> userProfiles = new DataAccess().getAllUserProfileExcept(currentUser.Email.ToLower()); if (leaveCancelationUiRender.isValid()) { var data = System.IO.File.ReadAllText(Server.MapPath("~/App_Data/request-number-tracker.db")); string newRequestId = (long.Parse(data, System.Globalization.NumberStyles.AllowThousands | System.Globalization.NumberStyles.AllowLeadingSign) + 1).ToString(); NeuLeaveCancelation neuLeaveCancelation = new NeuLeaveCancelation(); neuLeaveCancelation.UserId = currentUser.Id; neuLeaveCancelation.RequestId = newRequestId; neuLeaveCancelation.Message = leaveCancelationUiRender.message; neuLeaveCancelation.StartDate = leaveCancelationUiRender.leaveStartDate; neuLeaveCancelation.EndDate = leaveCancelationUiRender.leaveEndDate; neuLeaveCancelation.AddedOn = dateCreated; neuLeaveCancelation.ModifiedOn = dateCreated; int newRequestInternId = new DataAccess().addNewLeaveCancelation(neuLeaveCancelation); if (newRequestInternId != -1) { NueRequestMaster nueRequestMaster = new NueRequestMaster(); nueRequestMaster.RequestId = newRequestId; nueRequestMaster.CreatedBy = currentUser.Id; nueRequestMaster.IsApprovalProcess = 1; nueRequestMaster.RequestStatus = 1; nueRequestMaster.PayloadId = newRequestInternId; nueRequestMaster.RequestCatType = 1; nueRequestMaster.AddedOn = dateCreated; nueRequestMaster.ModifiedOn = dateCreated; int newRequestTempInternId = new DataAccess().addNeuRequest(nueRequestMaster); if (newRequestTempInternId != -1) { List <NueRequestAceessLog> nueRequestAceessLogs = new List <NueRequestAceessLog>(); NueRequestAceessLog nueRequestAceessLog = new NueRequestAceessLog(); nueRequestAceessLog.RequestId = newRequestTempInternId; nueRequestAceessLog.UserId = currentUser.Id; nueRequestAceessLog.OwnerId = currentUser.Id; nueRequestAceessLog.Completed = 1; nueRequestAceessLog.AddedOn = dateCreated; nueRequestAceessLog.ModifiedOn = dateCreated; nueRequestAceessLogs.Add(nueRequestAceessLog); nueRequestAceessLog = new NueRequestAceessLog(); nueRequestAceessLog.RequestId = newRequestTempInternId; nueRequestAceessLog.UserId = int.Parse(leaveCancelationUiRender.leaveCancelationApprover); nueRequestAceessLog.OwnerId = currentUser.Id; nueRequestAceessLog.Completed = 0; nueRequestAceessLog.AddedOn = dateCreated; nueRequestAceessLog.ModifiedOn = dateCreated; nueRequestAceessLogs.Add(nueRequestAceessLog); new DataAccess().addNeuRequestAccessLogs(nueRequestAceessLogs); System.IO.File.WriteAllText(Server.MapPath("~/App_Data/request-number-tracker.db"), newRequestId); return(RedirectToAction("Index")); } else { throw new Exception("An error occerd"); } } else { throw new Exception("An error occerd"); } } else { ViewData["UserMasterList"] = userProfiles; ViewData["UserProfileSession"] = (Session["UserProfileSession"] as UserProfile); ViewData["LeaveCancelationUiRender"] = leaveCancelationUiRender; TempData["Message"] = "Invalid request"; return(View()); } } catch (Exception e) { List <UserProfile> userProfiles = new DataAccess().getAllUserProfileExcept(currentUser.Email.ToLower()); ViewData["UserMasterList"] = userProfiles; ViewData["UserProfileSession"] = (Session["UserProfileSession"] as UserProfile); ViewData["LeaveCancelationUiRender"] = leaveCancelationUiRender; TempData["Message"] = "Invalid request"; return(View()); } }