Beispiel #1
0
        public JsonResult SaveAlternateApprover(LeaveApprovalModel model)
        {
            try
            {
                string           EmpID          = model.EmployeeID;
                string           LeaveRequestID = model.LeaveRequestId.ToString();
                Zftm0006Response z = new Zftm0006Response();

                z.DETAILS    = new ZFTM0006_TAB[6];
                z.DETAILS[0] = new ZFTM0006_TAB();
                if (_rfcconfig.GetSection("StaticValue").GetSection("EMobNo").Value != "")
                {
                    z.DETAILS[0].CELL_SUP    = _rfcconfig.GetSection("StaticValue").GetSection("EMobNo").Value;
                    z.DETAILS[0].EMAIL_SUP   = _rfcconfig.GetSection("StaticValue").GetSection("EmailApr").Value;
                    z.DETAILS[0].EMAILID_HOD = _rfcconfig.GetSection("StaticValue").GetSection("EMailHOD").Value;
                    z.DETAILS[0].PERNR_SUP   = _rfcconfig.GetSection("StaticValue").GetSection("AprID").Value;
                    z.DETAILS[0].CNAME_SUP   = _rfcconfig.GetSection("StaticValue").GetSection("AprName").Value;
                }
                else
                {
                    z.DETAILS[0].PERNR_SUP   = model.ApproverId.Trim();     //model.Select(x=>x.ApproverId).ToString();
                    z.DETAILS[0].CNAME_SUP   = model.ApproverName.Trim();   //model.leaveApprovals.Select(x => x.ApproverName).ToString();
                    z.DETAILS[0].CELL_SUP    = model.ApproverMobNo.Trim();  //model.leaveApprovals.Select(x => x.ApproverMobNo).ToString();
                    z.DETAILS[0].EMAIL_SUP   = model.ApproverMailID.Trim(); //model.leaveApprovals.Select(x => x.ApproverMailID).ToString();
                    z.DETAILS[0].EMAILID_HOD = model.HODMailID.Trim();      // model.leaveApprovals.Select(x => x.HODMailID).ToString();
                }
                z.DETAILS[0].PERNR_HOD = model.HODID;                       //model.leaveApprovals.Select(x => x.HODID).ToString();
                z.DETAILS[0].CNAME_HOD = model.HODName;                     // model.leaveApprovals.Select(x => x.HODName).ToString();

                z.DETAILS[0].EmployeeID     = EmpID;
                z.DETAILS[0].LeaveRequestID = LeaveRequestID.ToString();
                var datareturn = _ILeaveRequestViewService.SaveApproverFromSAP(Mapper.Map <ApproverServiceModel>(z));
                var msg        = "saved";
                return(Json(new { result = msg, msg = msg }));
                //return Json(msg);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                return(Json(string.Empty));
            }
        }
Beispiel #2
0
        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);
        }