public PartialViewResult _Categories()
        {
            var userData = MvcApplication.GetUserData(User.Identity.Name);

            if (userData == null || userData.UserId < 1)
            {
                return(PartialView(new List <ExpenseCategoryObj>()));
            }

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

            var retVal = ExpenseLookUpServices.LoadExpenseCategories(searchObj, userData.Username);

            if (retVal?.Status == null)
            {
                return(PartialView(new List <ExpenseCategoryObj>()));
            }

            if (!retVal.Status.IsSuccessful)
            {
                return(PartialView(new List <ExpenseCategoryObj>()));
            }

            if (!retVal.ExpenseCategories.Any())
            {
                return(PartialView(new List <ExpenseCategoryObj>()));
            }

            var categories = retVal.ExpenseCategories.Where(c => c.Status == 1).OrderBy(c => c.ExpenseCategoryId);

            return(PartialView(categories));
        }
Пример #2
0
        public ActionResult Index(int?clientId, int?productId)
        {
            try
            {
                ViewBag.Error = "";

                #region Client Product productItem Session Check

                var userClientSession = (AppSession)Session["_UserClientSession_"];
                if (userClientSession == null || userClientSession.ClientId < 1 || userClientSession.ProductId < 1 || userClientSession.ProductItemId < 1)
                {
                    return(RedirectToAction("Index", "Dashboard"));
                }
                var ClientId      = clientId ?? userClientSession.ClientId;
                var ProductId     = productId ?? userClientSession.ProductId;
                var ProductItemId = userClientSession.ProductItemId;

                #endregion

                #region Current User Session Check
                var userData = MvcApplication.GetUserData(User.Identity.Name);
                if (userData == null || userData.UserId < 1)
                {
                    ViewBag.Error = "Session Has Expired! Please Re-Login";
                    return(View(new List <ExpenseItemSettingObj>()));
                }

                #endregion

                #region Other Objects Names
                var categorySearchObj = new ExpenseCategorySearchObj
                {
                    AdminUserId       = userData.UserId,
                    ExpenseCategoryId = 0,
                    Status            = 1
                };

                var classificationSearchObj = new ExpenseClassificationSearchObj()
                {
                    AdminUserId             = userData.UserId,
                    ExpenseClassificationId = 0,
                    Status = 1
                };


                var typeSearchObj = new ExpenseTypeSearchObj()
                {
                    AdminUserId   = userData.UserId,
                    ExpenseTypeId = 0,
                    Status        = 1
                };
                var itemSearchObj = new ExpenseItemSearchObj()
                {
                    AdminUserId   = userData.UserId,
                    ExpenseItemId = 0,
                    Status        = 1
                };


                #endregion

                #region Client Expense Item And Dependent Objects Session Check


                if (Session["_ExpenseItemSettingList_"] is List <ExpenseItemSettingObj> ExpenseItemSetting && ExpenseItemSetting.Any())
                {
                    if (Session["_Category_"] is List <ExpenseCategoryObj> expenseCategorys && !expenseCategorys.Any())
                    {
                        Session["_Category_"] = new List <ExpenseCategoryObj>();
                    }
                    if (Session["_Classification_"] is List <ExpenseClassificationObj> expenseClassifications && !expenseClassifications.Any())
                    {
                        Session["_Classification_"] = new List <ExpenseCategoryObj>();
                    }
                    if (Session["_Types_"] is List <ExpenseTypeObj> expenseType && !expenseType.Any())
                    {
                        Session["_Types_"] = new List <ExpenseCategoryObj>();
                    }
                    if (Session["_Items_"] is List <ExpenseItemObj> expenseItem && !expenseItem.Any())
                    {
                        Session["_Items_"] = new List <ExpenseItemObj>();
                    }
                    var clientExpenseItemList = ExpenseItemSetting.Where(m => m.ClientId == ClientId && m.ProductId == ProductId).ToList();
                    return(View(clientExpenseItemList));
                }

                #endregion

                #region Request and response Validations

                var searchObj = new ExpenseItemSettingSearchObj
                {
                    AdminUserId          = userData.UserId,
                    ExpenseItemSettingId = 0,
                    Status = 1
                };
                var retVal = ExpenseItemSettingServices.LoadExpenseItemSettings(searchObj, userData.Username);
                if (retVal?.Status == null)
                {
                    ViewBag.Error = " ExpenseItemSetting list is empty!";
                    return(View(new List <ExpenseItemSettingObj>()));
                }

                if (!retVal.Status.IsSuccessful)
                {
                    ViewBag.Error = string.IsNullOrEmpty(retVal.Status.Message.FriendlyMessage)
                        ? " ExpenseItemSetting list is empty!"
                        : retVal.Status.Message.FriendlyMessage;
                    return(View(new List <ExpenseItemSettingObj>()));
                }
                if (retVal.ExpenseItemSettings == null || !retVal.ExpenseItemSettings.Any())
                {
                    ViewBag.Error = " ExpenseItemSetting list is empty!";
                    return(View(new List <ExpenseItemSettingObj>()));
                }

                #endregion

                #region Initialize object Lists to sessions


                var categoryRetVal = ExpenseLookUpServices.LoadExpenseCategories(categorySearchObj, userData.Username);
                var catList        = categoryRetVal.ExpenseCategories.OrderBy(m => m.ExpenseCategoryId).ToList();
                Session["_Category_"] = catList;

                var classificationRetVal = ExpenseLookUpServices.LoadClassifications(classificationSearchObj, userData.Username);
                var classificationList   = classificationRetVal.ExpenseClassifications.OrderBy(m => m.ExpenseClassificationId).ToList();
                Session["_Classification_"] = classificationList;

                var typeRetVal = ExpenseLookUpServices.LoadExpenseTypes(typeSearchObj, userData.Username);
                var typeList   = typeRetVal.ExpenseTypes.OrderBy(m => m.ExpenseTypeId).ToList();
                Session["_Types_"] = typeList;

                var itemRetVal = ExpenseLookUpServices.LoadExpenseItems(itemSearchObj, userData.Username);
                var itemList   = itemRetVal.ExpenseItems.OrderBy(m => m.ExpenseItemId).ToList();
                Session["_Items_"] = itemList;

                var ExpenseItemSettings = retVal.ExpenseItemSettings.OrderBy(m => m.ExpenseItemSettingId).ToList();
                Session["_ExpenseItemSettingList_"] = ExpenseItemSettings.Where(m =>
                                                                                m.ClientId == ClientId && m.ProductId == ProductId).ToList();


                #endregion

                var clientProdExpItemList = ExpenseItemSettings.Where(m =>
                                                                      m.ClientId == ClientId && m.ProductId == ProductId).ToList();

                return(View(clientProdExpItemList));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(View(new List <ExpenseItemSettingObj>()));
            }
        }