public IActionResult AddMasterCountry()
        {
            try
            {
                AddMasterCountryViewModel objAddMasterCountryViewModel = new AddMasterCountryViewModel();
                objAddMasterCountryViewModel.Mode            = CommonFunction.Mode.SAVE;
                objAddMasterCountryViewModel.IsActive        = true;
                objAddMasterCountryViewModel.MasterCountryId = CommonFunction.NextMasterId("ADMasterCountry", apiBaseUrl);
                objAddMasterCountryViewModel.MasterCountryId = 0;
                objAddMasterCountryViewModel.CountryTitle    = "";
                objAddMasterCountryViewModel.CountryCode     = "";
                objAddMasterCountryViewModel.CountryDialCode = "";
                objAddMasterCountryViewModel.CountryFlag     = "";
                //DropDownFillMethod();

                //Return View doesn't make a new requests, it just renders the view
                return(View("~/Views/Master/MasterCountry/AddMasterCountry.cshtml", objAddMasterCountryViewModel));
            }
            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());
        }
        public IActionResult ViewMasterCountry(long MasterCountryId)
        {
            try
            {
                AddMasterCountryViewModel objAddMasterCountryViewModel = null;
                string        endpoint        = apiBaseUrl + "MasterCountries/" + MasterCountryId;
                Task <string> HttpGetResponse = CommonFunction.GetWebAPI(endpoint);

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

                //DropDownFillMethod();
                objAddMasterCountryViewModel.Mode = CommonFunction.Mode.UPDATE;
                return(View("~/Views/Master/MasterCountry/AddMasterCountry.cshtml", objAddMasterCountryViewModel));
            }
            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());
        }
        public IActionResult SaveMasterCountry(AddMasterCountryViewModel objAddMasterCountryViewModel)
        {
            try
            {
                objAddMasterCountryViewModel.EnterById    = 1;
                objAddMasterCountryViewModel.EnterDate    = DateTime.Now;
                objAddMasterCountryViewModel.ModifiedById = 1;
                objAddMasterCountryViewModel.ModifiedDate = DateTime.Now;

                if (objAddMasterCountryViewModel.IsActive == null)
                {
                    objAddMasterCountryViewModel.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 + "MasterCountries";

                    Task <string> HttpPostResponse = null;

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

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

                    if (HttpPostResponse != null)
                    {
                        objAddMasterCountryViewModel = JsonConvert.DeserializeObject <AddMasterCountryViewModel>(HttpPostResponse.Result);
                        _logger.LogInformation("Database Insert/Update: ");//+ JsonConvert.SerializeObject(objAddMasterCountryViewModel)); ;
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        //DropDownFillMethod();
                        ModelState.Clear();
                        ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                        return(View("~/Views/Master/MasterCountry/AddMasterCountry.cshtml", objAddMasterCountryViewModel));
                    }
                }
                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/MasterCountry/AddMasterCountry.cshtml", objAddMasterCountryViewModel));
                }
            }
            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());
        }