//
        // GET: /Menu/Details/By ID
        public ActionResult Details(int id)
        {
            var errorViewModel = new ErrorViewModel();

            try
            {
                //var menu = _menuRepository.GetById(id);
                var menu = _menuRepository.GetAll().SingleOrDefault(x => x.MenuId == id);
                if (menu != null)
                {
                    var singleOrDefaultParentMenu = _menuRepository.GetAll().SingleOrDefault(x => x.MenuId == menu.ParentMenuId);

                    var singleOrDefaultApplication = _applicationRepository.GetAll().SingleOrDefault(x => x.ApplicationId == menu.ApplicationId);

                    var singleOrDefaultModule = _moduleRepository.GetAll().SingleOrDefault(x => x.ModuleId == menu.ModuleId);

                    if (singleOrDefaultApplication != null && singleOrDefaultModule != null)
                    {
                        var viewModel = new MenuViewModel() { MenuId = menu.MenuId, MenuName = menu.MenuName, MenuCaption = menu.MenuCaption, MenuCaptionBng = menu.MenuCaptionBng, PageUrl = menu.PageUrl, SerialNo = Convert.ToInt32(menu.SerialNo), OrderNo = Convert.ToInt32(menu.OrderNo), ParentMenuId = Convert.ToInt32(menu.ParentMenuId), ParentMenuName = singleOrDefaultParentMenu.MenuName, ApplicationId = menu.ApplicationId, ApplicationName = singleOrDefaultApplication.ApplicationName, ModuleId = menu.ModuleId, ModuleName = singleOrDefaultModule.ModuleName };

                        return PartialView("_Details", viewModel);
                    }
                }

                errorViewModel = ExceptionHelper.ExceptionErrorMessageForNullObject();
            }
            catch (Exception ex)
            {
                errorViewModel = ExceptionHelper.ExceptionErrorMessageFormat(ex);
            }

            return PartialView("_ErrorPopup", errorViewModel);
        }
        public static ErrorViewModel ExceptionErrorMessageFormat(Exception ex)
        {
            var errorViewModel = new ErrorViewModel();

            string message = "Error: There was a problem while processing your request: " + ex.Message;

            if (ex.InnerException != null)
            {
                Exception inner = ex.InnerException;
                if (inner is System.Data.Common.DbException)
                    message = "Database is currently experiencing problems. " + inner.Message;
                else if (inner is System.Data.UpdateException)
                    message = "Datebase is currently updating problem.";
                else if (inner is System.Data.EntityException)
                    message = "Entity is problem.";
                else if (inner is NullReferenceException)
                    message = "There are one or more required fields that are missing.";
                else if (inner is ArgumentException)
                {
                    string paramName = ((ArgumentException)inner).ParamName;
                    message = string.Concat("The ", paramName, " value is illegal.");
                }
                else if (inner is ApplicationException)
                    message = "Exception in application" + inner.Message;
                else
                    message = inner.Message;

            }

            errorViewModel.ErrorType = "error";
            errorViewModel.ErrorMessage = message;

            return errorViewModel;
        }
        //
        // GET: /Module/Details/By ID
        public ActionResult Details(int id)
        {
            var errorViewModel = new ErrorViewModel();

            try
            {
                //var module = _moduleRepository.GetById(id);
                var module = _moduleRepository.GetAll().SingleOrDefault(x => x.ModuleId == id);
                if (module != null)
                {
                    var singleOrDefault = _applicationRepository.GetAll().SingleOrDefault(x => x.ApplicationId == module.ApplicationId);
                    if (singleOrDefault != null)
                    {
                        var viewModel = new ModuleViewModel() { ModuleId = module.ModuleId, ModuleName = module.ModuleName, Description = module.Description, ModuleTitle = module.ModuleTitle, ApplicationId = module.ApplicationId, ApplicationName = singleOrDefault.ApplicationName };
                        return PartialView("_Details", viewModel);
                    }
                }

                errorViewModel = ExceptionHelper.ExceptionErrorMessageForNullObject();
            }
            catch (Exception ex)
            {
                errorViewModel = ExceptionHelper.ExceptionErrorMessageFormat(ex);
            }

            return PartialView("_ErrorPopup", errorViewModel);
        }
        public static ErrorViewModel ExceptionErrorMessageForNullObject()
        {
            var errorViewModel = new ErrorViewModel();

            string message = "Requested object could not found.";

            errorViewModel.ErrorType = "warn";
            errorViewModel.ErrorMessage = message;

            return errorViewModel;
        }
        public static ErrorViewModel ExceptionErrorMessageForCommon()
        {
            var errorViewModel = new ErrorViewModel();

            string message = "Oops! Exception in application.";

            errorViewModel.ErrorType = "info";
            errorViewModel.ErrorMessage = message;

            return errorViewModel;
        }
        //
        // GET: /CostOrExpense/Details/By ID
        public ActionResult Details(int id)
        {
            var errorViewModel = new ErrorViewModel();

            try
            {
                var costOrExpense = _db.CostOrExpenses.Find(id);
                if (costOrExpense != null)
                {
                    var viewModel = new CostOrExpenseViewModel() { CostOrExpenseId = costOrExpense.CostOrExpenseId, Amount = costOrExpense.Amount, CreateDate = costOrExpense.CreateDate, Remarks = costOrExpense.Remarks, AccountId = costOrExpense.AccountId, AccountName = costOrExpense.Account != null ? costOrExpense.Account.AccountName : "", CostOrExpenseCategoryId = costOrExpense.CostOrExpenseCategoryId, CostOrExpenseCategoryName = costOrExpense.CostOrExpenseCategory != null ? costOrExpense.CostOrExpenseCategory.CostOrExpenseCategoryName : "" };
                    return PartialView("_Details", viewModel);
                }

                errorViewModel = ExceptionHelper.ExceptionErrorMessageForNullObject();
            }
            catch (Exception ex)
            {
                errorViewModel = ExceptionHelper.ExceptionErrorMessageFormat(ex);
            }

            return PartialView("_ErrorPopup", errorViewModel);
        }
        //
        // GET: /Currency/Details/By ID
        public ActionResult Details(int id)
        {
            var errorViewModel = new ErrorViewModel();

            try
            {
                var currency = _db.Currencies.Find(id);
                if (currency != null)
                {
                    var viewModel = new CurrencyViewModel() { CurrencyId = currency.CurrencyId, CurrencyName = currency.CurrencyName };
                    return PartialView("_Details", viewModel);
                }

                errorViewModel = ExceptionHelper.ExceptionErrorMessageForNullObject();
            }
            catch (Exception ex)
            {
                errorViewModel = ExceptionHelper.ExceptionErrorMessageFormat(ex);
            }

            return PartialView("_ErrorPopup", errorViewModel);
        }
        //
        // GET: /AppSetting/Details/By ID
        public ActionResult Details(int id)
        {
            var errorViewModel = new ErrorViewModel();

            try
            {
                var appSettings = _db.AppSettings.Find(id);
                if (appSettings != null)
                {
                    var viewModel = new AppSettingsViewModel() { AppSettingsId = appSettings.AppSettingsId, Name = appSettings.Name };
                    return PartialView("_Details", viewModel);
                }

                errorViewModel = ExceptionHelper.ExceptionErrorMessageForNullObject();
            }
            catch (Exception ex)
            {
                errorViewModel = ExceptionHelper.ExceptionErrorMessageFormat(ex);
            }

            return PartialView("_ErrorPopup", errorViewModel);
        }
        //
        // GET: /SaleOrIncomeCategory/Details/By ID
        public ActionResult Details(int id)
        {
            var errorViewModel = new ErrorViewModel();

            try
            {
                var saleOrIncomeCategory = _db.SaleOrIncomeCategories.Find(id);
                if (saleOrIncomeCategory != null)
                {
                    var viewModel = new SaleOrIncomeCategoryViewModel() { SaleOrIncomeCategoryId = saleOrIncomeCategory.SaleOrIncomeCategoryId, SaleOrIncomeCategoryName = saleOrIncomeCategory.SaleOrIncomeCategoryName };
                    return PartialView("_Details", viewModel);
                }

                errorViewModel = ExceptionHelper.ExceptionErrorMessageForNullObject();
            }
            catch (Exception ex)
            {
                errorViewModel = ExceptionHelper.ExceptionErrorMessageFormat(ex);
            }

            return PartialView("_ErrorPopup", errorViewModel);
        }
        //
        // GET: /CostOrExpenseCategory/Details/By ID
        public ActionResult Details(int id)
        {
            var errorViewModel = new ErrorViewModel();

            try
            {
                var costOrExpenseCategory = _db.CostOrExpenseCategories.Find(id);
                if (costOrExpenseCategory != null)
                {
                    var viewModel = new CostOrExpenseCategoryViewModel() { CostOrExpenseCategoryId = costOrExpenseCategory.CostOrExpenseCategoryId, CostOrExpenseCategoryName = costOrExpenseCategory.CostOrExpenseCategoryName };
                    return PartialView("_Details", viewModel);
                }

                errorViewModel = ExceptionHelper.ExceptionErrorMessageForNullObject();
            }
            catch (Exception ex)
            {
                errorViewModel = ExceptionHelper.ExceptionErrorMessageFormat(ex);
            }

            return PartialView("_ErrorPopup", errorViewModel);
        }
        //
        // GET: /SaleOrIncome/Details/By ID
        public ActionResult Details(int id)
        {
            var errorViewModel = new ErrorViewModel();

            try
            {
                var saleOrIncome = _db.SaleOrIncomes.Find(id);
                if (saleOrIncome != null)
                {
                    var viewModel = new SaleOrIncomeViewModel() { SaleOrIncomeId = saleOrIncome.SaleOrIncomeId, UnitPrice = saleOrIncome.UnitPrice, Quantity = saleOrIncome.Quantity, ProcessCostRate = saleOrIncome.ProcessCostRate, ExtraCostAmount = saleOrIncome.ExtraCostAmount, CreateDate = saleOrIncome.CreateDate, Remarks = saleOrIncome.Remarks, AccountId = saleOrIncome.AccountId, AccountName = saleOrIncome.Account != null ? saleOrIncome.Account.AccountName : "", SaleOrIncomeCategoryId = saleOrIncome.SaleOrIncomeCategoryId, SaleOrIncomeCategoryName = saleOrIncome.SaleOrIncomeCategory != null ? saleOrIncome.SaleOrIncomeCategory.SaleOrIncomeCategoryName : "" };

                    return PartialView("_Details", viewModel);
                }

                errorViewModel = ExceptionHelper.ExceptionErrorMessageForNullObject();
            }
            catch (Exception ex)
            {
                errorViewModel = ExceptionHelper.ExceptionErrorMessageFormat(ex);
            }

            return PartialView("_ErrorPopup", errorViewModel);
        }
        //
        // GET: /Application/Details/By ID
        public ActionResult Details(int id)
        {
            var errorViewModel = new ErrorViewModel();

            try
            {
                //var application = _applicationRepository.GetById(id);
                var application = _applicationRepository.GetAll().SingleOrDefault(x => x.ApplicationId == id);
                if (application != null)
                {
                    var viewModel = new ApplicationViewModel() { ApplicationId = application.ApplicationId, ApplicationName = application.ApplicationName, Description = application.Description, ApplicationTitle = application.ApplicationTitle };
                    return PartialView("_Details", viewModel);
                }

                errorViewModel = ExceptionHelper.ExceptionErrorMessageForNullObject();
            }
            catch (Exception ex)
            {
                errorViewModel = ExceptionHelper.ExceptionErrorMessageFormat(ex);
            }

            return PartialView("_ErrorPopup", errorViewModel);
        }
        //
        // GET: /CostOrExpense/Edit/By ID
        public ActionResult Edit(int id)
        {
            var errorViewModel = new ErrorViewModel();

            try
            {
                var costOrExpense = _db.CostOrExpenses.Find(id);
                if (costOrExpense != null)
                {
                    var accountList = SelectListItemExtension.PopulateDropdownList(_db.Accounts.ToList<Account>(), "AccountId", "AccountName", isEdit: true, selectedValue: costOrExpense.AccountId.ToString()).ToList();
                    var costOrExpenseCategoryList = SelectListItemExtension.PopulateDropdownList(_db.CostOrExpenseCategories.ToList<CostOrExpenseCategory>(), "CostOrExpenseCategoryId", "CostOrExpenseCategoryName", isEdit: true, selectedValue: costOrExpense.CostOrExpenseCategoryId.ToString()).ToList();

                    var viewModel = new CostOrExpenseViewModel() { CostOrExpenseId = costOrExpense.CostOrExpenseId, Amount = costOrExpense.Amount, CreateDate = costOrExpense.CreateDate, Remarks = costOrExpense.Remarks, AccountId = costOrExpense.AccountId, AccountName = costOrExpense.Account != null ? costOrExpense.Account.AccountName : "", ddlAccounts = accountList, CostOrExpenseCategoryId = costOrExpense.CostOrExpenseCategoryId, CostOrExpenseCategoryName = costOrExpense.CostOrExpenseCategory != null ? costOrExpense.CostOrExpenseCategory.CostOrExpenseCategoryName : "", ddlCostOrExpenseCategories = costOrExpenseCategoryList };

                    return PartialView("_AddOrEdit", viewModel);
                }

                errorViewModel = ExceptionHelper.ExceptionErrorMessageForNullObject();
            }
            catch (Exception ex)
            {
                errorViewModel = ExceptionHelper.ExceptionErrorMessageFormat(ex);
            }

            return PartialView("_ErrorPopup", errorViewModel);
        }
        //
        // GET: /SaleOrIncome/Edit/By ID
        public ActionResult Edit(int id)
        {
            var errorViewModel = new ErrorViewModel();

            try
            {
                var saleOrIncome = _db.SaleOrIncomes.Find(id);
                if (saleOrIncome != null)
                {
                    var accountList = SelectListItemExtension.PopulateDropdownList(_db.Accounts.ToList<Account>(), "AccountId", "AccountName", isEdit: true, selectedValue: saleOrIncome.AccountId.ToString()).ToList();
                    var saleOrIncomeCategoryList = SelectListItemExtension.PopulateDropdownList(_db.SaleOrIncomeCategories.ToList<SaleOrIncomeCategory>(), "SaleOrIncomeCategoryId", "SaleOrIncomeCategoryName", isEdit: true, selectedValue: saleOrIncome.SaleOrIncomeCategoryId.ToString()).ToList();

                    var viewModel = new SaleOrIncomeViewModel() { SaleOrIncomeId = saleOrIncome.SaleOrIncomeId, UnitPrice = saleOrIncome.UnitPrice, Quantity = saleOrIncome.Quantity, ProcessCostRate = saleOrIncome.ProcessCostRate, ExtraCostAmount = saleOrIncome.ExtraCostAmount, CreateDate = saleOrIncome.CreateDate, Remarks = saleOrIncome.Remarks, AccountId = saleOrIncome.AccountId, AccountName = saleOrIncome.Account != null ? saleOrIncome.Account.AccountName : "", ddlAccounts = accountList, SaleOrIncomeCategoryId = saleOrIncome.SaleOrIncomeCategoryId, SaleOrIncomeCategoryName = saleOrIncome.SaleOrIncomeCategory != null ? saleOrIncome.SaleOrIncomeCategory.SaleOrIncomeCategoryName : "", ddlSaleOrIncomeCategories = saleOrIncomeCategoryList };

                    return PartialView("_AddOrEdit", viewModel);
                }

                errorViewModel = ExceptionHelper.ExceptionErrorMessageForNullObject();
            }
            catch (Exception ex)
            {
                errorViewModel = ExceptionHelper.ExceptionErrorMessageFormat(ex);
            }

            return PartialView("_ErrorPopup", errorViewModel);
        }
        //
        // GET: /Module/Edit/By ID
        public ActionResult Edit(int id)
        {
            var errorViewModel = new ErrorViewModel();

            try
            {
                //var module = _moduleRepository.GetById(id);
                var module = _moduleRepository.GetAll().SingleOrDefault(x => x.ModuleId == id);
                if (module != null)
                {
                    var applicationList = SelectListItemExtension.PopulateDropdownList(_applicationRepository.GetAll().ToList<TblApplication>(), "ApplicationId", "ApplicationName", isEdit: true, selectedValue: module.ApplicationId.ToString()).ToList();

                    var singleOrDefault = _applicationRepository.GetAll().SingleOrDefault(x => x.ApplicationId == module.ApplicationId);
                    if (singleOrDefault != null)
                    {

                        var viewModel = new ModuleViewModel()
                        {
                            ModuleId = module.ModuleId,
                            ModuleName = module.ModuleName,
                            Description = module.Description,
                            ModuleTitle = module.ModuleTitle,
                            ApplicationId = module.ApplicationId,
                            ApplicationName = singleOrDefault.ApplicationName,
                            ddlApplications = applicationList
                        };
                        return PartialView("_AddOrEdit", viewModel);
                    }
                }

                errorViewModel = ExceptionHelper.ExceptionErrorMessageForNullObject();
            }
            catch (Exception ex)
            {
                errorViewModel = ExceptionHelper.ExceptionErrorMessageFormat(ex);
            }

            return PartialView("_ErrorPopup", errorViewModel);
        }
        //
        // GET: /Menu/Edit/By ID
        public ActionResult Edit(int id)
        {
            var errorViewModel = new ErrorViewModel();

            try
            {
                //var menu = _menuRepository.GetById(id);
                var menu = _menuRepository.GetAll().SingleOrDefault(x => x.MenuId == id);
                if (menu != null)
                {
                    var parentMenuList = SelectListItemExtension.PopulateDropdownList(_menuRepository.GetAll().ToList<TblMenu>(), "MenuId", "MenuName", isEdit: true, selectedValue: menu.ParentMenuId.ToString()).ToList();

                    var moduleList = SelectListItemExtension.PopulateDropdownList(_moduleRepository.GetAll().ToList<TblModule>(), "ModuleId", "ModuleName", isEdit: true, selectedValue: menu.ModuleId.ToString()).ToList();

                    var applicationList = SelectListItemExtension.PopulateDropdownList(_applicationRepository.GetAll().ToList<TblApplication>(), "ApplicationId", "ApplicationName", isEdit: true, selectedValue: menu.ApplicationId.ToString()).ToList();

                    var singleOrDefaultParentMenu = _menuRepository.GetAll().SingleOrDefault(x => x.MenuId == menu.ParentMenuId);

                    var singleOrDefaultApplication = _applicationRepository.GetAll().SingleOrDefault(x => x.ApplicationId == menu.ApplicationId);

                    var singleOrDefaultModule = _moduleRepository.GetAll().SingleOrDefault(x => x.ModuleId == menu.ModuleId);

                    if (singleOrDefaultApplication != null && singleOrDefaultModule != null)
                    {

                        var viewModel = new MenuViewModel()
                        {
                            MenuId = menu.MenuId,
                            MenuName = menu.MenuName,
                            MenuCaption = menu.MenuCaption,
                            MenuCaptionBng = menu.MenuCaptionBng,
                            PageUrl = menu.PageUrl,
                            SerialNo = Convert.ToInt32(menu.SerialNo),
                            OrderNo = Convert.ToInt32(menu.OrderNo),
                            ParentMenuId = Convert.ToInt32(menu.ParentMenuId),
                            ParentMenuName = singleOrDefaultParentMenu.MenuName,
                            ddlParentMenus = parentMenuList,
                            ApplicationId = menu.ApplicationId,
                            ApplicationName = singleOrDefaultApplication.ApplicationName,
                            ddlApplications = applicationList,
                            ModuleId = menu.ModuleId,
                            ModuleName = singleOrDefaultModule.ModuleName,
                            ddlModules = moduleList
                        };
                        return PartialView("_AddOrEdit", viewModel);
                    }
                }

                errorViewModel = ExceptionHelper.ExceptionErrorMessageForNullObject();
            }
            catch (Exception ex)
            {
                errorViewModel = ExceptionHelper.ExceptionErrorMessageFormat(ex);
            }

            return PartialView("_ErrorPopup", errorViewModel);
        }