コード例 #1
0
        public IActionResult Index()
        {
            try
            {
                IndexGenCodeTypeViewModel          objIndexGenCodeTypeViewModel = new IndexGenCodeTypeViewModel();
                IEnumerable <GenCodeTypeViewModel> objGenCodeTypeViewModellList = null;
                string        endpoint        = apiBaseUrl + "GenCodeTypes";
                Task <string> HttpGetResponse = CommonFunction.GetWebAPI(endpoint);

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

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

                objIndexGenCodeTypeViewModel.GenCodeTypeList = objGenCodeTypeViewModellList.ToList();

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

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

                //Return View doesn't make a new requests, it just renders the view
                return(View("~/Views/Administrator/GenCodeType/Index.cshtml", objIndexGenCodeTypeViewModel));
            }
            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());
        }