Exemplo n.º 1
0
        public IActionResult PrintMasterSubCategory()
        {
            try
            {
                IndexMasterSubCategoryViewModel          objIndexMasterSubCategoryViewModel = new IndexMasterSubCategoryViewModel();
                IEnumerable <MasterSubCategoryViewModel> objMasterSubCategoryViewModelList  = null;

                string        endpoint        = assetsApiBaseUrl + "MasterSubCategory";
                Task <string> HttpGetResponse = CommonFunction.GetWebAPI(endpoint);

                if (HttpGetResponse != null)
                {
                    objMasterSubCategoryViewModelList = JsonConvert.DeserializeObject <IEnumerable <MasterSubCategoryViewModel> >(HttpGetResponse.Result).ToList();
                }
                else
                {
                    objMasterSubCategoryViewModelList = Enumerable.Empty <MasterSubCategoryViewModel>().ToList();

                    ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                }

                objIndexMasterSubCategoryViewModel.MasterSubCategoryList = objMasterSubCategoryViewModelList.OrderBy(a => a.SubCategoryTitle).ToList();

                string             filePath = $"{webHostEnvironment.WebRootPath}\\Reports\\MasterSubCategory.pdf";
                System.IO.FileInfo DelFile  = new System.IO.FileInfo(filePath);

                if (DelFile.Exists)
                {
                    DelFile.Delete();
                }

                var report = new ViewAsPdf("~/Views/Assets/MasterSubCategory/PrintMasterSubCategory.cshtml", objIndexMasterSubCategoryViewModel)
                {
                    MinimumFontSize = 10,
                    PageMargins     = { Left = 10, Bottom = 10, Right = 10, Top = 5 },
                    //FileName =  "MasterSubCategory.pdf",
                    PageOrientation = Rotativa.AspNetCore.Options.Orientation.Portrait,
                    //CustomSwitches = "--page-offset 0 --footer-center [page] --footer-font-size 12",
                    CustomSwitches = "--footer-center \"  Created Date: " + DateTime.Now.Date.ToString("dd/MM/yyyy") + "  Page: [page]/[toPage]\"" +
                                     " --footer-line --footer-font-size \"10\" --footer-spacing 1 --footer-font-name \"Segoe UI\"",
                    PageSize = Rotativa.AspNetCore.Options.Size.A4,
                };
                return(report);
            }
            catch (Exception ex)
            {
                string ActionName     = this.ControllerContext.RouteData.Values["action"].ToString();
                string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
                string ErrorMessage   = "Controler:" + ControllerName + " , Action:" + ActionName + " , Exception:" + ex.Message;

                _logger.LogError(ErrorMessage);
                return(View("~/Views/Shared/Error.cshtml", CommonFunction.HandleErrorInfo(ex, ActionName, ControllerName)));
            }
            return(new EmptyResult());
        }
Exemplo n.º 2
0
        public IActionResult Index()
        {
            try
            {
                IndexMasterSubCategoryViewModel          objIndexMasterSubCategoryViewModel = new IndexMasterSubCategoryViewModel();
                IEnumerable <MasterSubCategoryViewModel> objMasterSubCategoryViewModelList  = null;

                string        endpoint        = assetsApiBaseUrl + "MasterSubCategory";
                Task <string> HttpGetResponse = CommonFunction.GetWebAPI(endpoint);

                if (HttpGetResponse != null)
                {
                    objMasterSubCategoryViewModelList = JsonConvert.DeserializeObject <IEnumerable <MasterSubCategoryViewModel> >(HttpGetResponse.Result).ToList();
                }
                else
                {
                    objMasterSubCategoryViewModelList = Enumerable.Empty <MasterSubCategoryViewModel>().ToList();

                    ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                }

                objIndexMasterSubCategoryViewModel.MasterSubCategoryList = objMasterSubCategoryViewModelList.OrderBy(a => a.SubCategoryTitle).ToList();

                //############# Profile Maping ###################
                CPanelManager.ViewModels.Account.ValidateAccountViewModel objValidateAccountViewModel = CommonFunction.ActionResultAuthentication(HttpContext, "/MasterSubCategory/Index");

                if (objValidateAccountViewModel != null)
                {
                    objIndexMasterSubCategoryViewModel.IsSelect = objValidateAccountViewModel.IsSelect;
                    objIndexMasterSubCategoryViewModel.IsInsert = objValidateAccountViewModel.IsInsert;
                    objIndexMasterSubCategoryViewModel.IsUpdate = objValidateAccountViewModel.IsUpdate;
                    objIndexMasterSubCategoryViewModel.IsDelete = objValidateAccountViewModel.IsDelete;
                }
                //############# Profile Maping End ###################

                //Return View doesn't make a new requests, it just renders the view
                return(View("~/Views/Assets/MasterSubCategory/Index.cshtml", objIndexMasterSubCategoryViewModel));
            }
            catch (Exception ex)
            {
                string ActionName     = this.ControllerContext.RouteData.Values["action"].ToString();
                string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
                string ErrorMessage   = "Controler:" + ControllerName + " , Action:" + ActionName + " , Exception:" + ex.Message;

                _logger.LogError(ErrorMessage);
                return(View("~/Views/Shared/Error.cshtml", CommonFunction.HandleErrorInfo(ex, ActionName, ControllerName)));
            }
            return(new EmptyResult());
        }