public JsonResult ProcessAddRequestTypeSettingRequest(RegRequestTypeSettingObj model)
        {
            try
            {
                #region Current User Session Check

                var userData = MvcApplication.GetUserData(User.Identity.Name) ?? new UserData();
                if (userData.UserId < 1)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }

                #endregion

                #region Model Validations Check

                if (model == null)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }

                if (model.ClientId < 1)
                {
                    return(Json(new { isauthenticated = true, issuccessful = false, isreload = false, error = "client required " }));
                }

                if (model.ProductItemId < 1)
                {
                    return(Json(new { isauthenticated = true, issuccessful = false, isreload = false, error = "Product Item required " }));
                }

                if (model.ProductId < 1)
                {
                    return(Json(new { isauthenticated = true, issuccessful = false, isreload = false, error = "Product required " }));
                }

                if (model.RequestType < 1)
                {
                    return(Json(new { isauthenticated = true, issuccessful = false, isreload = false, error = "Product required " }));
                }

                #endregion

                #region Check if Item Already Exist from Session


                var requestTypeSettingList = (List <RequestTypeSetting>)Session["_RequestTypeSettingList_"];
                if (requestTypeSettingList != null)
                {
                    if (requestTypeSettingList.Any(x => x.RequestType == model.RequestType &&
                                                   x.ClientId == model.ClientId &&
                                                   x.ProductId == model.ProductId &&
                                                   x.ProductItemId == model.ProductItemId))
                    {
                        return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Request Type Already Exist!" }));
                    }
                }

                #endregion

                #region Build Request Object

                var requestObj = new RegRequestTypeSettingObj
                {
                    ClientId             = model.ClientId,
                    ProductId            = model.ProductId,
                    AdminUserId          = userData.UserId,
                    Status               = 1,
                    ProductItemId        = model.ProductItemId,
                    AllowedTaskTimeSpan  = model.AllowedTaskTimeSpan,//Convert.ToInt32(UtilTools.CurrentTimeStamp()),
                    AmountAllowed        = model.AmountAllowed,
                    RequestType          = model.RequestType,
                    TimeElapseAction     = 1,//Convert.ToInt32(DateTime.Now.Day), //model.TimeElapseAction,
                    TimeStampRegistered  = UtilTools.CurrentTimeStamp(),
                    RequestFrequencyType = model.RequestFrequencyType,
                };

                #endregion

                #region Request and response validations checks

                var response = RequestTypeSettingServices.AddRequestTypeSetting(requestObj, userData.Username);
                if (response?.Status == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Please try again later" }));
                }

                if (!response.Status.IsSuccessful)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = string.IsNullOrEmpty(response.Status.Message.TechnicalMessage) ? "Process Failed! Unable to add nomination Source" : response.Status.Message.TechnicalMessage }));
                }


                var searchObj = new RequestTypeSettingSearchObj
                {
                    AdminUserId          = userData.UserId,
                    RequestTypeSettingId = 0,
                    Status    = 1,
                    StartDate = "",
                    StopDate  = "",
                };

                var retVal = RequestTypeSettingServices.LoadRequestTypeSettings(searchObj, userData.Username);
                if (retVal?.Status != null && retVal.RequestTypeSettings != null)
                {
                    var RequestTypeSettings = retVal.RequestTypeSettings.OrderBy(m => m.RequestTypeSettingId).ToList();
                    Session["_RequestTypeSettingList_"] = RequestTypeSettings.Where(m => m.ClientId == model.ClientId &&
                                                                                    m.ProductId == model.ProductId &&
                                                                                    m.ProductItemId == model.ProductItemId).ToList();;
                }


                #endregion

                return(Json(new { IsAuthenticated = true, IsSuccessful = true, IsReload = false, Error = "" }));
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Process Error Occurred! Please try again later" }));
            }
        }
        public JsonResult ProcessEditRequestTypeSettingRequest(RequestTypeSetting model)
        {
            try
            {
                #region Current User session check

                var userData = MvcApplication.GetUserData(User.Identity.Name) ?? new UserData();

                if (userData.UserId < 1)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }

                #endregion

                var selRequestTypeSetting = Session["_CurrentSelRequestTypeSetting_"] as RequestTypeSetting;

                #region Model validation check

                if (selRequestTypeSetting == null || selRequestTypeSetting.RequestTypeSettingId < 1)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }

                if (model.ClientId < 1)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Client required " }));
                }
                if (model.RequestTypeSettingId < 1)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "RequestTypeSettingId required" }));
                }
                if (!GenericVal.Validate(model, out var msg))
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = $"Validation Error Occurred! Detail: {msg}" }));
                }
                #endregion

                #region Check if item already exist from Session

                var requestTypeSettingList = (List <RequestTypeSetting>)Session["_RequestTypeSettingList_"];
                if (requestTypeSettingList != null)
                {
                    if (requestTypeSettingList.Count(x => x.RequestType == model.RequestType &&
                                                     x.ClientId == model.ClientId &&
                                                     x.ProductId == model.ProductId &&
                                                     x.ProductItemId == model.ProductItemId &&
                                                     x.RequestTypeSettingId != model.RequestTypeSettingId) > 0)
                    {
                        return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Request Type Already Exist!" }));
                    }
                }


                #endregion

                #region Build request Object

                var requestObj = new EditRequestTypeSettingObj
                {
                    ClientId             = model.ClientId,
                    ProductId            = model.ProductId,
                    AdminUserId          = userData.UserId,
                    Status               = 1,
                    ProductItemId        = model.ProductItemId,
                    AllowedTaskTimeSpan  = model.AllowedTaskTimeSpan,//Convert.ToInt32(UtilTools.CurrentTimeStamp()),
                    AmountAllowed        = model.AmountAllowed,
                    RequestType          = model.RequestType,
                    TimeElapseAction     = 1,//Convert.ToInt32(DateTime.Now.Day), //model.TimeElapseAction,
                    TimeStampRegistered  = UtilTools.CurrentTimeStamp(),
                    RequestFrequencyType = model.RequestFrequencyType,
                    RequestTypeSettingId = model.RequestTypeSettingId,
                };

                #endregion

                #region Request and response validations

                var response = RequestTypeSettingServices.UpdateRequestTypeSetting(requestObj, userData.Username);
                if (response?.Status == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Please try again later" }));
                }

                if (!response.Status.IsSuccessful)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = string.IsNullOrEmpty(response.Status.Message.TechnicalMessage) ? "Process Failed! Unable to add course of study" : response.Status.Message.TechnicalMessage }));
                }

                Session["_CurrentSelRequestTypeSetting_"] = null;

                var searchObj = new RequestTypeSettingSearchObj
                {
                    AdminUserId          = userData.UserId,
                    RequestTypeSettingId = 0,
                    Status = -2
                };


                var retVal = RequestTypeSettingServices.LoadRequestTypeSettings(searchObj, userData.Username);
                if (retVal?.Status != null && retVal.RequestTypeSettings != null)
                {
                    var RequestTypeSettings = retVal.RequestTypeSettings.OrderBy(m => m.RequestTypeSettingId).ToList();
                    Session["_RequestTypeSettingList_"] = RequestTypeSettings.Where(m => m.ClientId == model.ClientId &&
                                                                                    m.ProductId == model.ProductId &&
                                                                                    m.ProductItemId == model.ProductItemId).ToList();
                }

                #endregion

                return(Json(new { IsAuthenticated = true, IsSuccessful = true, IsReload = false, Error = "" }));
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Process Error Occurred! Please try again later" }));
            }
        }
Exemplo n.º 3
0
        public JsonResult ProcessAddRetirementRequest(ExpenseRequisitionObj model, List <HttpPostedFileBase> ImageFile)
        {
            try
            {
                #region current User session check
                var userData = MvcApplication.GetUserData(User.Identity.Name) ?? new UserData();
                //if (userData.UserId < 1)
                //{
                //    //return Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false });
                //    return RedirectToAction("RetirementModule", new { clientId = model.ClientId, productId = model.ProductId, productItemId = model.ProductItemId, msg = "Your session has expired" });
                //}
                #endregion

                #region model Validation


                if (model.ExpenseRequisitionId < 1)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Unable to process  item" }));
                }

                if (string.IsNullOrEmpty(model.RecievedItemIds))
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Recieved Item not found" }));
                }

                if (string.IsNullOrEmpty(model.AmountRetired))
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Amount Retired" }));
                }

                if (string.IsNullOrEmpty(model.AmountSpent))
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Amount Spent" }));
                }

                if (model.RetirementMode < 1)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Retirement Mode" }));
                }

                if (string.IsNullOrEmpty(model.VoucherNumber))
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Voucher Number" }));
                }
                #endregion

                #region  Get Expense Disbursed from Disbursement Service
                var searchObjForDis = new DisbursementSearchObj
                {
                    AdminUserId    = userData.UserId,
                    DisbursementId = 0,
                    StartDate      = "",
                    Status         = 2,
                    StopDate       = "",
                    VoucheNumber   = ""
                };
                var retValForDis = DisbursementServices.LoadDisbursements(searchObjForDis, userData.Username);
                if (retValForDis.Status == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Unable to process  item" }));
                }

                var disbursementList = retValForDis.Disbursements.OrderBy(x => x.DisbursementId).ToList();
                var expenseDisbursed = disbursementList.SingleOrDefault(m => m.ExpenseRequisitionId == model.ExpenseRequisitionId);
                if (expenseDisbursed == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Unable to process  item" }));
                }
                #endregion

                #region Get Expense form Expense Service

                var searchExpObj = new ExpenseSearchObj
                {
                    AdminUserId = userData.UserId,
                    ExpenseId   = 0,
                    Status      = -1000,
                    StartDate   = " ",
                    StopDate    = " ",
                };
                var retValExp   = ExpenseRequisitionServices.LoadExpenses(searchExpObj, userData.Username);
                var thisExpense = retValExp.Expenses.SingleOrDefault(m => m.ExpenseId == expenseDisbursed.ExpenseId);
                if (thisExpense == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Unable to process  item" }));
                }

                #endregion

                #region Build Retirement Request Object

                List <RegReceiptObj> recs = new List <RegReceiptObj>();

                foreach (var file in ImageFile)
                {
                    var rec = new RegReceiptObj()
                    {
                        ExpenseId                = expenseDisbursed.ExpenseId,
                        ExpenseRequisitionId     = expenseDisbursed.ExpenseRequisitionId,
                        ReceiptDocument          = GetBytesFromFile(file),
                        ReceiptNunber            = model.RecievedItemIds,
                        ReceiptFileName          = Path.GetFileName(file.FileName),
                        ExpenseRequisitionItemId = model.RecievedItemIds,
                    };
                    recs.Add(rec);
                }


                var requestObj = new RegRetirementObj
                {
                    ClientId             = expenseDisbursed.ClientId,
                    ProductId            = expenseDisbursed.ProductId,
                    AdminUserId          = userData.UserId,
                    ProductItemId        = expenseDisbursed.ProductItemId,
                    RequestType          = expenseDisbursed.RequestType,
                    Title                = expenseDisbursed.Title,
                    BeneficiaryType      = expenseDisbursed.BeneficiaryType,
                    AmountRetired        = Convert.ToDecimal(model.AmountRetired),
                    BeneficiaryId        = expenseDisbursed.BeneficiaryId,
                    ExpenseId            = expenseDisbursed.ExpenseId,
                    ExpenseRequisitionId = Convert.ToInt32(model.ExpenseRequisitionId),
                    RetiredBy            = userData.UserId,
                    RetirementMode       = model.RetirementMode,
                    TimeStampRetired     = UtilTools.CurrentTimeStamp(),
                    VoucherNumber        = model.VoucherNumber,
                    WorkflowItemId       = Convert.ToInt32(expenseDisbursed.WorkflowItemId),
                    DisbursementId       = expenseDisbursed.DisbursementId,
                    RecievedItemIds      = model.RecievedItemIds,
                    RetirementType       = model.RetirementMode,
                    Receipts             = recs,
                };
                #endregion

                #region Response and Validations
                var response = RetirementServices.AddRetirement(requestObj, userData.Username);
                if (response?.Status == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Please try again later" }));
                }

                if (!response.Status.IsSuccessful)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = string.IsNullOrEmpty(response.Status.Message.TechnicalMessage) ? "Process Failed! Unable to Process Data" : response.Status.Message.TechnicalMessage }));
                }

                #endregion

                #region Request and Response Validations

                var searchObj = new DisbursementSearchObj
                {
                    AdminUserId    = userData.UserId,
                    DisbursementId = 0,
                    StartDate      = "",
                    Status         = (int)DisbursementStatus.Awaiting_Retirement,
                    StopDate       = "",
                    VoucheNumber   = ""
                };
                var retVal = DisbursementServices.LoadDisbursements(searchObj, userData.Username);
                if (retVal?.Status == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = string.IsNullOrEmpty(response.Status.Message.TechnicalMessage) ? "Process Failed! Unable to Process Data" : response.Status.Message.TechnicalMessage }));
                }

                if (retVal.Disbursements == null || !retVal.Disbursements.Any())
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = string.IsNullOrEmpty(response.Status.Message.TechnicalMessage) ? "Process Failed! Unable to Process Data" : response.Status.Message.TechnicalMessage }));
                }
                Session["_currentExpenseDisbursement_"] = retVal.Disbursements.Where(x => x.ClientId == model.ClientId && x.ProductId == model.ProductId).ToList();
                #endregion


                Session["_ListOfExpReqItems_"] = null;
                return(Json(new { IsAuthenticated = true, IsSuccessful = true, IsReload = true, Error = "" }));
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Process Error Occurred! Please try again later" }));
            }
        }