Example #1
0
        public IActionResult AddMasterCity()
        {
            try
            {
                AddMasterCityViewModel objAddMasterCityViewModel = new AddMasterCityViewModel();
                objAddMasterCityViewModel.Mode          = CommonFunction.Mode.SAVE;
                objAddMasterCityViewModel.IsActive      = true;
                objAddMasterCityViewModel.MasterCityId  = CommonFunction.NextMasterId("ADMasterCity", apiBaseUrl);
                objAddMasterCityViewModel.MasterCityId  = 0;
                objAddMasterCityViewModel.CityTitle     = "";
                objAddMasterCityViewModel.MasterStateId = 0;
                DropDownFillMethod();

                //Return View doesn't make a new requests, it just renders the view
                return(View("~/Views/Master/MasterCity/AddMasterCity.cshtml", objAddMasterCityViewModel));
            }
            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());
        }
Example #2
0
        public IActionResult ViewMasterCity(long MasterCityId)
        {
            try
            {
                AddMasterCityViewModel objAddMasterCityViewModel = null;
                string        endpoint        = apiBaseUrl + "MasterCities/" + MasterCityId;
                Task <string> HttpGetResponse = CommonFunction.GetWebAPI(endpoint);

                if (HttpGetResponse != null)
                {
                    objAddMasterCityViewModel = JsonConvert.DeserializeObject <AddMasterCityViewModel>(HttpGetResponse.Result);
                }
                else
                {
                    objAddMasterCityViewModel = new AddMasterCityViewModel();
                    ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                }

                DropDownFillMethod();
                objAddMasterCityViewModel.Mode = CommonFunction.Mode.UPDATE;
                return(View("~/Views/Master/MasterCity/AddMasterCity.cshtml", objAddMasterCityViewModel));
            }
            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());
        }
Example #3
0
        public IActionResult SaveMasterCity(AddMasterCityViewModel objAddMasterCityViewModel)
        {
            try
            {
                objAddMasterCityViewModel.EnterById    = 1;
                objAddMasterCityViewModel.EnterDate    = DateTime.Now;
                objAddMasterCityViewModel.ModifiedById = 1;
                objAddMasterCityViewModel.ModifiedDate = DateTime.Now;

                if (objAddMasterCityViewModel.IsActive == null)
                {
                    objAddMasterCityViewModel.IsActive = false;
                }

                var errors = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => new { x.Key, x.Value.Errors }).ToArray();

                if (ModelState.IsValid)
                {
                    string endpoint = apiBaseUrl + "MasterCities";

                    Task <string> HttpPostResponse = null;

                    if (objAddMasterCityViewModel.Mode == CommonFunction.Mode.SAVE)
                    {
                        HttpPostResponse = CommonFunction.PostWebAPI(endpoint, objAddMasterCityViewModel);
                        //Notification Message
                        //Session is used to store object
                        HttpContext.Session.SetObjectAsJson("GlobalMessage", CommonFunction.GlobalMessage(1, 2, 4, "Master City", "Master City Insert Successfully!", ""));
                    }
                    else if (objAddMasterCityViewModel.Mode == CommonFunction.Mode.UPDATE)
                    {
                        endpoint         = apiBaseUrl + "MasterCities/" + objAddMasterCityViewModel.MasterCityId;
                        HttpPostResponse = CommonFunction.PutWebAPI(endpoint, objAddMasterCityViewModel);

                        //Notification Message
                        //Session is used to store object
                        HttpContext.Session.SetObjectAsJson("GlobalMessage", CommonFunction.GlobalMessage(1, 2, 4, "Master City", "Master City Update Successfully!", ""));
                    }

                    if (HttpPostResponse != null)
                    {
                        objAddMasterCityViewModel = JsonConvert.DeserializeObject <AddMasterCityViewModel>(HttpPostResponse.Result);
                        _logger.LogInformation("Database Insert/Update: ");//+ JsonConvert.SerializeObject(objAddGenCodeTypeViewModel)); ;
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        DropDownFillMethod();
                        ModelState.Clear();
                        ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                        return(View("~/Views/Master/MasterCity/AddMasterCity.cshtml", objAddMasterCityViewModel));
                    }
                }
                else
                {
                    ModelState.Clear();
                    if (ModelState.IsValid == false)
                    {
                        ModelState.AddModelError(string.Empty, "Validation error. Please contact administrator.");
                    }

                    DropDownFillMethod();

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