public IActionResult ApproverLogin(ApproverLogin loginViewModel) { if (!ModelState.IsValid) { return(View()); } try { var empid = ""; loginViewModel.Password = AESEncrytDecry.DecryptStringAES(loginViewModel.Password); var result = AdLogin(loginViewModel.UserId, loginViewModel.Password, loginViewModel.MailID, loginViewModel.Mobileno, out empid, out string userName, out string firstname); if (!result) { ViewBag.Messages = new[] { new AlertModel("danger", "Warning!", "Entered Credentials Did Not Match") }; return(View()); } else { var EmpID = loginViewModel.UserId; var employeeid = empid; if (employeeid.Length != 8) { employeeid = employeeid.ToString().PadLeft(8, '0'); } Tuple <string, int> Result = _Ileaveapprovalservice.InsertEmpId(employeeid); if (Result.Item2 == 0) { TempData["loginendtime"] = Result.Item1; return(RedirectToAction("LoginTimeout", "Home")); } HttpContext.Session.SetString(Constant.ApproverID, employeeid); HttpContext.Session.SetString(Constant.AdminID, employeeid); HttpContext.Session.SetString(Constant.SessionUserName, userName); HttpContext.Session.SetString(Constant.SessionModulName, "Approver"); HttpContext.Session.SetString("FirstName", firstname); ViewBag.UserName = HttpContext.Session.GetString(Constant.SessionUserName); LeaveApprovalModelViewModel approverLogin = new LeaveApprovalModelViewModel(); string ModuleName = HttpContext.Session.GetString(Constant.SessionModulName); var MenuItem = _imenuservice.GetMenu(ModuleName, employeeid); MenuviewModel model = new MenuviewModel(); model.MenuModels = Mapper.Map <List <MenuModel> >(MenuItem); HttpContext.Session.SetObjectAsJson <MenuviewModel>(Constant.Menu, model); return(RedirectToAction("ApproverDashboard", "LeaveApprover")); } } catch (Exception ex) { _logger.LogError(ex, ex.Message); ViewBag.Messages = new[] { new AlertModel("danger", "Warning!", "Entered Credentials Did Not Match") }; return(View()); } }
public IActionResult LeaveApproval(string LeaveRequestID, string status) { string returnmsg = ""; try { LeaveRequestID = LeaveRequestID.Replace(",,", ""); LeaveApprovalModelViewModel model = new LeaveApprovalModelViewModel(); model = Mapper.Map <LeaveApprovalModelViewModel>(_iLeaveapprovalService.GetMulitpleEmployeeDetails(LeaveRequestID)); LeaveApprovalModelViewModel model2 = new LeaveApprovalModelViewModel(); model2 = model; returnmsg = SaveDataToSAP(model, status); } catch (Exception ex) { _logger.LogError(ex, ex.Message); ViewBag.Messages = new[] { new AlertModel("danger", "Warning!", ex.Message) }; } return(Json(new { valid = returnmsg.Split('~')[0], msg = returnmsg.Split('~')[1] })); }
public string SaveDataToSAP(LeaveApprovalModelViewModel modellist, string status) { bool valid = false; string msg = ""; try { string Mobileno = ""; string MobilenoR = ""; string Approverid = (HttpContext.Session.GetString(Constant.ApproverID)); dynamic indicator = ""; dynamic errormsg = ""; if (status == "Approved") { try { foreach (var model in modellist.leaveApprovals) { bool error = false; string deletion = ""; if (model.OldStatus == "Pending Withdrawal") { status = "Withdrawal"; deletion = "X"; } else { deletion = ""; } model.FromDateString = model.FromDateString.Replace('-', '/'); model.ToDateString = model.ToDateString.Replace('-', '/'); string esbfromdate = model.FromDateString.Split("/")[1] + "/" + model.FromDateString.Split("/")[0] + "/" + model.FromDateString.Split("/")[2]; string esbtodate = model.ToDateString.Split("/")[1] + "/" + model.ToDateString.Split("/")[0] + "/" + model.ToDateString.Split("/")[2]; string param = "leaves?pernr_001=" + model.EmployeeID + "&subty_006=" + model.LeaveCode + "&begda_007=" + esbfromdate + "&endda_008=" + esbtodate + "&full_first_sec=" + model.LeaveShift + "&simulation=" + "" + "&Deletion=" + deletion; using (HttpClient client = new HttpClient()) { string apiUrl = _rfcconfig.GetSection("MySettings").GetSection("WebApiBaseUrl").Value + param; client.BaseAddress = new Uri(apiUrl); client.Timeout = TimeSpan.FromMinutes(5); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); var responsecli = client.GetAsync(apiUrl); var data = responsecli.Result; if (data.IsSuccessStatusCode) { var readTask = data.Content.ReadAsStringAsync(); LEAVEREQUESTDETAILS leaveRequestDetails = JsonConvert.DeserializeObject <LEAVEREQUESTDETAILS>(readTask.Result); if (leaveRequestDetails != null && leaveRequestDetails.IT_ERROR_TEXT != null) { foreach (var detail in leaveRequestDetails.IT_ERROR_TEXT) { if (detail.IND == "E") { error = true; errormsg = detail.TEXT; indicator = detail.IND; } } if (error == false) { errormsg = "Successfully updated in SAP"; indicator = "S"; } } } else { _logger.LogError("Gateway Timeout Error" + model.EmployeeID); } } model.ErrorMsg = errormsg; model.Indicator = indicator; model.ApproverId = Approverid; model.Status = error == true ? "Error" : status; } Tuple <string, int> result = _iLeaveapprovalService.SaveLeaveApproval(Mapper.Map <LeaveApprovalServiceViewModel>(modellist)); LeaveApprovalModel leavemodel = new LeaveApprovalModel(); if (result.Item2 != -99) { if (status == "Approved" || status == "Withdrawal") { foreach (var model in modellist.leaveApprovals) { // Mobileno = model.empmobileno;//mobileno add #region Message for Approved record to Employee if (result.Item2 != -99) { var msgTextapprover = ""; if (model.OldStatus == "Pending Withdrawal") { msgTextapprover = "Your Subordinate wants to cancel/ withdraw below leave/attendance requests which were approved in the system." + Environment.NewLine + "Please approve / reject the request accordingly" + Environment.NewLine; Mobileno = model.ApproverMobNo;// "8149102368"; } else { msgTextapprover = "Your below mentioned leaves/attendance requests submitted have been approved." + Environment.NewLine; Mobileno = model.empmobileno;//mobileno add "8149102368";// } var mesg = msgTextapprover + Environment.NewLine + "Employee No:-" + model.EmployeeID + Environment.NewLine + "Request:-" + model.LeaveCategory + Environment.NewLine + "From Date:-" + model.FromDateString + Environment.NewLine + "To Date:-" + model.ToDateString + Environment.NewLine + "Days:-" + model.TotalLeaves + " days"; try { _SMSUtility.SendSMS(Mobileno, mesg); } catch (Exception) { } } } } #endregion } if (result.Item2 != -99) { if (status == "Approved" || status == "Withdrawal") { msg = "LeaveRequest has been Approved successfully.... "; } else { msg = "LeaveRequest has been Rejected successfully.... "; } valid = true; } else { msg = "Error Occured while processing the request...."; valid = false; } } catch (Exception ex) { valid = false; msg = "Error Occured while processing the request...."; _logger.LogError(ex, ex.Message); } } //for reject code else { foreach (var model in modellist.leaveApprovals) { model.ErrorMsg = ""; model.Indicator = "W"; model.ApproverId = Approverid; if (status == "Rejected" && model.OldStatus == "Pending Withdrawal") { model.Status = "Withdrawal Rejected"; } else { model.Status = status; } } Tuple <string, int> result = _iLeaveapprovalService.SaveLeaveApproval(Mapper.Map <LeaveApprovalServiceViewModel>(modellist)); LeaveApprovalModel leavemodel = new LeaveApprovalModel(); if (result.Item2 != -99) { foreach (var model in modellist.leaveApprovals) { if (result.Item2 != -99) { MobilenoR = model.empmobileno;//mobileno add #region Message for Reject record var msgTextapprover = "Your below mentioned leaves / attendance requests have been rejected." + Environment.NewLine + "Employee No:-" + model.EmployeeID + Environment.NewLine + "Request:-" + model.LeaveCategory + Environment.NewLine + "From Date:-" + model.FromDateString + Environment.NewLine + "To Date:-" + model.ToDateString + Environment.NewLine + "Days:-" + model.TotalLeaves + " days"; try { _SMSUtility.SendSMS(MobilenoR.ToString(), msgTextapprover); } catch (Exception) { } } } #endregion msg = "LeaveRequest has been Rejected successfully.... "; valid = true; } else { msg = "Error Occured while processing the request...."; valid = false; } } } catch (Exception ex) { valid = false; msg = "Error Occured while processing the request...."; _logger.LogError(ex, ex.Message); } return(valid + "~" + msg); }