Пример #1
0
        public static ExpenseItemSettingRegRespObj UpdateExpenseItemSetting(EditExpenseItemSettingObj regObj, string username)
        {
            var response = new ExpenseItemSettingRegRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage(),
                },
            };

            try
            {
                var apiResponse = new APIHelper(APIEndpoints.UPDATE_EXPENSE_ITEM_SETTING_ENDPOINT, username, Method.POST).ProcessAPI <EditExpenseItemSettingObj, ExpenseItemSettingRegRespObj>(regObj, out var msg);
                if (msg.Code == 0 && string.IsNullOrEmpty(msg.TechMessage) && string.IsNullOrEmpty(msg.Message))
                {
                    return(apiResponse);
                }

                response.Status.Message.FriendlyMessage  = msg.Message;
                response.Status.Message.TechnicalMessage = msg.TechMessage;
                return(response);
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.GetBaseException().Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                return(response);
            }
        }
Пример #2
0
        public JsonResult ProcessEditExpenseItemSettingRequest(ExpenseItemSettingObj model)
        {
            try
            {
                #region 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 Check if Item Session is null
                var selExpenseItemSetting = Session["_CurrentSelExpenseItemSetting_"] as ExpenseItemSettingObj;
                if (selExpenseItemSetting == null || selExpenseItemSetting.ExpenseItemSettingId < 1)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }
                #endregion

                #region Model Validations

                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.ExpenseCategoryId < 1)
                {
                    return(Json(new { isauthenticated = true, issuccessful = false, isreload = false, error = "ExpenseCategory required " }));
                }
                if (model.ExpenseClassificationId < 1)
                {
                    return(Json(new { isauthenticated = true, issuccessful = false, isreload = false, error = "Expense Classification required " }));
                }

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

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

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

                if (model.RequestFrequency < 1)
                {
                    return(Json(new { isauthenticated = true, issuccessful = false, isreload = false, error = "Request Frequency required " }));
                }
                if (model.RequestFrequencyType < 1)
                {
                    return(Json(new { isauthenticated = true, issuccessful = false, isreload = false, error = "Request Frequency Type required " }));
                }

                if (model.UnitPrice < 1)
                {
                    return(Json(new { isauthenticated = true, issuccessful = false, isreload = false, error = "Unit Price  required " }));
                }
                if (model.ExpenseItemSettingId < 1)
                {
                    return(Json(new { isauthenticated = true, issuccessful = false, isreload = false, error = "Unit Price  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 Build Request Object

                var passObj = new EditExpenseItemSettingObj()
                {
                    ClientId                = model.ClientId,
                    ProductId               = model.ProductId,
                    AdminUserId             = userData.UserId,
                    RegisteredBy            = userData.UserId,
                    ProductItemId           = model.ProductItemId,
                    ExpenseCategoryId       = model.ExpenseCategoryId,
                    ExpenseClassificationId = model.ExpenseClassificationId,
                    ExpenseItemId           = model.ExpenseItemId,
                    ExpenseTypeId           = model.ExpenseTypeId,
                    IsEnabled               = true,
                    PreferedVendorId        = model.PreferedVendorId,
                    RegularQuantity         = model.RegularQuantity,
                    RequestFrequency        = model.RequestFrequency,
                    RequestFrequencyType    = model.RequestFrequencyType,
                    Status               = 1,
                    UnitPrice            = model.UnitPrice,
                    ExpenseItemSettingId = model.ExpenseItemSettingId,
                };

                #endregion

                #region Response and Validations Check
                var response = ExpenseItemSettingServices.UpdateExpenseItemSetting(passObj, 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["_CurrentSelExpenseItemSetting_"] = null;

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

                var retVal = ExpenseItemSettingServices.LoadExpenseItemSettings(searchObj, userData.Username);
                if (retVal?.Status != null && retVal.ExpenseItemSettings != null)
                {
                    var ExpenseItemSettings = retVal.ExpenseItemSettings.OrderBy(m => m.ExpenseItemSettingId).ToList();
                    Session["_ExpenseItemSettingList_"] = ExpenseItemSettings.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" }));
            }
        }