public ActionResult Approval(int levelType) { var request = new Taxi_ApprovalDao().GetListApproval(mEmployee.employee.employee_id, levelType); ViewBag.ListRequests = request; return(View()); }
protected override void OnActionExecuting(ActionExecutingContext filterContext) { try { if (Request.Cookies["user_cookie"] != null) { var temp = Request.Cookies["user_cookie"].Value; mEmployee = JsonConvert.DeserializeObject <UserModel>(temp); } } catch { mEmployee = null; } if (mEmployee == null) { filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary(new { controller = "Login", action = "Index" })); return; } else { if (adWebHelper.getUserInfo(mEmployee.employee.access_token) != null) { // Set values from user here ViewBag.User = mEmployee.employee.display_name; var employeeInfor = adWebHelper.GetDetailUserInfo(mEmployee.employee.access_token, mEmployee.employee.employee_id); //var sml = adWebHelper.GetDetailUserInfoByID(mEmployee.employee.access_token, Convert.ToInt32(employeeInfor.parent_id[0].ToString())).ad_user_displayName; //var headInfor = adWebHelper.GetHeadOfFunction(mEmployee.employee.access_token, employeeInfor.department).ad_user_displayName; // send mail nao //adWebHelper.SendMail(mEmployee.employee.access_token); // get department department = adWebHelper.GetDepartments(mEmployee.employee.access_token); if (Session[CommonConstants.USER_SESSION] == null) { UpdateUserInformation(employeeInfor); } Session[CommonConstants.USER_SESSION] = employeeInfor; Session[CommonConstants.SESSION_CREDENTIALS] = new UserDao().GetListCredential(employeeInfor.ad_user_employeeID); TempData["ApprovalTotalL1"] = new Taxi_ApprovalDao().GetTotalApproval(mEmployee.employee.employee_id, 1); TempData["ApprovalTotalL2"] = new Taxi_ApprovalDao().GetTotalApproval(mEmployee.employee.employee_id, 2); TempData["Pesmission"] = new UserDao().GetListCredential(employeeInfor.ad_user_employeeID); base.OnActionExecuting(filterContext); } else { filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary(new { controller = "Login", action = "Index" })); return; } } }
public ActionResult Approval(List <ApprovalModel> approval) { bool check = true; foreach (var item in approval) { if (item.type != 0) { // set approval tbl_Taxi_Approval_Infor approve = new tbl_Taxi_Approval_Infor(); approve.Request_Id = item.Id; approve.Process = item.process; approve.ApproverId = mEmployee.employee.employee_id; approve.Remark = (item.comment != null) ? item.comment.ToString() : null; approve.UpdateDate = DateTime.Now; approve.State = item.type; var approvalDao = new Taxi_ApprovalDao().InsertOrUpdateApproval(approve); // If approve process 2 -> insert new row var resultNew = true; if (item.type == 1 && item.process == 1) { tbl_Taxi_Approval_Infor approveNew = new tbl_Taxi_Approval_Infor(); approveNew.Request_Id = item.Id; approveNew.Process = 2; approveNew.UpdateDate = DateTime.Now; approveNew.State = 0; approveNew.DepartmentName = DepartmentLevel2; resultNew = new Taxi_ApprovalDao().InsertOrUpdateApproval(approveNew); } if (!approvalDao || resultNew == false) { check = false; } } } if (check == true) { Notification("Success", "Approval request successfully", MyConstants.NOTIFY_SUCCESS); TempData["ApprovalTotalL1"] = new Taxi_ApprovalDao().GetTotalApproval(mEmployee.employee.employee_id, 1); TempData["ApprovalTotalL2"] = new Taxi_ApprovalDao().GetTotalApproval(mEmployee.employee.employee_id, 2); } else { Notification("False", "Approval request failure, error: ", MyConstants.NOTIFY_ERROR); } return(RedirectToAction("Approval")); }
public JsonResult DeleteRequest(Guid id, string listReceptions, string reason) { if (listReceptions != null && listReceptions != "") { // send mail new Taxi_RequestDao().SendMailRemove(id, listReceptions, reason, mEmployee.employee.display_name); } // check and delete permisstion var approvalResult = new Taxi_ApprovalDao().RemoveApprovalByRequestId(id); var visitorResult = new Taxi_UserDao().RemoveUserByRequestId(id); var requestResult = new Taxi_RequestDao().RemoveRequest(id); if (approvalResult && visitorResult && requestResult) // if not exists in deputy list or head => delete permisstion approval { return(Json(new { status = true })); } else { return(Json(new { status = false })); } }
public JsonResult DeleteListRequest(List <Guid> listRequest) { bool check = true; foreach (var item in listRequest) { // check and delete permisstion var approvalResult = new Taxi_ApprovalDao().RemoveApprovalByRequestId(item); var visitorResult = new Taxi_UserDao().RemoveUserByRequestId(item); var requestResult = new Taxi_RequestDao().RemoveRequest(item); if (!approvalResult || !visitorResult || !requestResult) { check = false; } } if (check) // if not exists in deputy list or head => delete permisstion approval { return(Json(new { status = true })); } else { return(Json(new { status = false })); } }
public ActionResult CreateRequest(CreateRequestModel request) { try { // Insert request infor tbl_Taxi_Request_Infor taxiInfor = new tbl_Taxi_Request_Infor(); taxiInfor.Id = request.Id; taxiInfor.EmployeeId = request.EmployeeId; taxiInfor.Purpose = request.Purpose; taxiInfor.ScheduleTime = request.ScheduleTime; taxiInfor.Head = adWebHelper.GetHeadOfFunction(mEmployee.employee.access_token, mEmployee.employee.departmentName).ad_user_displayName; taxiInfor.Pickup = request.Pickup; taxiInfor.DropOff1 = request.DropOff1; taxiInfor.DropOff2 = request.DropOff2; taxiInfor.CreateDate = DateTime.Now; taxiInfor.Remark = request.Remark; var resultRequest = new Taxi_RequestDao().InsertOrUpdateRequest(taxiInfor); // Insert personal infor var checkInsertDetail = true; if (request.ListVisitorCSV != "" && request.ListVisitorCSV != null) { System.IO.File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "\\TempCSV.csv", request.ListVisitorCSV, System.Text.Encoding.UTF8); List <CSVModel> values = System.IO.File.ReadAllLines(AppDomain.CurrentDomain.BaseDirectory + "\\TempCSV.csv") .Skip(1) .Select(v => FromCsv(v)) .ToList(); foreach (var item in values) { if (checkInsertDetail == true) { tbl_Taxi_User_Infor user = new tbl_Taxi_User_Infor(); user.Name = item.VisitorName; user.EmployeeId = item.NationalId; user.SLM_Name = item.CompanyName; user.Taxi_Request_Infor_Id = request.Id; user.Remark = item.Remark; user.Taxi_Request_Infor_Id = request.Id; // Two record if register dropoff 2 if (request.DropOff2 != "" && request.DropOff2 != null) { user.Process = 1; checkInsertDetail = new Taxi_UserDao().InsertOrUpdateUser(user); user.Process = 2; } checkInsertDetail = new Taxi_UserDao().InsertOrUpdateUser(user); } } } else { foreach (var item in request.Visitor) { if (checkInsertDetail == true) { item.Taxi_Request_Infor_Id = request.Id; // Two record if register dropoff 2 if (request.DropOff2 != "" && request.DropOff2 != null) { item.Process = 1; checkInsertDetail = new Taxi_UserDao().InsertOrUpdateUser(item); item.Process = 2; } checkInsertDetail = new Taxi_UserDao().InsertOrUpdateUser(item); } } } // Insert approval infor tbl_Taxi_Approval_Infor approval = new tbl_Taxi_Approval_Infor(); approval.Request_Id = (Guid)request.Id; approval.DepartmentName = mEmployee.employee.departmentName; approval.Process = 1; approval.State = 0; approval.UpdateDate = DateTime.Now; var resultApproval = new Taxi_ApprovalDao().InsertOrUpdateApproval(approval); if (resultRequest == true && resultApproval == true && checkInsertDetail == true) { Notification("Success", "Create request successfully", MyConstants.NOTIFY_SUCCESS); return(RedirectToAction("Index", "Home", new { type = 0 })); } else { //Rollback - delete when failure var approvalDeleteResult = new Taxi_ApprovalDao().RemoveApprovalByRequestId(request.Id); var userDeleteResult = new Taxi_UserDao().RemoveUserByRequestId(request.Id); var requestDeleteResult = new Taxi_RequestDao().RemoveRequest(request.Id); WriteLogError.Write("Insert Request Failure: ", "Request: " + resultRequest + " Visitor: " + checkInsertDetail + " Approval: " + resultApproval); WriteLogError.Write("Rollback Request Failure: ", "Request: " + requestDeleteResult + " Visitor: " + userDeleteResult + " Approval: " + approvalDeleteResult); Notification("False", "Create request failure, Please recheck all information!", MyConstants.NOTIFY_ERROR); } } catch (Exception ex) { Notification("False", "Create request failure, error: " + ex.ToString(), MyConstants.NOTIFY_ERROR); } return(RedirectToAction("CreateRequest", "Request")); }