public IActionResult AddGenCodeMaster()
        {
            try
            {
                AddGenCodeMasterViewModel objAddGenCodeMasterViewModel = new AddGenCodeMasterViewModel();
                objAddGenCodeMasterViewModel.Mode               = CommonFunction.Mode.SAVE;
                objAddGenCodeMasterViewModel.IsActive           = true;
                objAddGenCodeMasterViewModel.GenCodeMasterId    = CommonFunction.NextMasterId("ADGenCodeMaster", apiBaseUrl);
                objAddGenCodeMasterViewModel.GenCodeMasterId    = 0;
                objAddGenCodeMasterViewModel.GenCodeMasterTitle = "";
                objAddGenCodeMasterViewModel.PrintDesc          = "";
                objAddGenCodeMasterViewModel.GenCodeTypeId      = 1;
                objAddGenCodeMasterViewModel.Sequence           = 1;
                DropDownFillMethod();

                //Return View doesn't make a new requests, it just renders the view
                return(View("~/Views/Master/GenCodeMaster/AddGenCodeMaster.cshtml", objAddGenCodeMasterViewModel));
            }
            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 ViewGenCodeMaster(long GenCodeMasterId)
        {
            try
            {
                AddGenCodeMasterViewModel objAddGenCodeMasterViewModel = null;
                string        endpoint        = apiBaseUrl + "GenCodeMasters/" + GenCodeMasterId;
                Task <string> HttpGetResponse = CommonFunction.GetWebAPI(endpoint);

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

                DropDownFillMethod();
                objAddGenCodeMasterViewModel.Mode = CommonFunction.Mode.UPDATE;
                return(View("~/Views/Master/GenCodeMaster/AddGenCodeMaster.cshtml", objAddGenCodeMasterViewModel));
            }
            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 SaveGenCodeMaster(AddGenCodeMasterViewModel objAddGenCodeMasterViewModel)
        {
            try
            {
                objAddGenCodeMasterViewModel.EnterById    = 1;
                objAddGenCodeMasterViewModel.EnterDate    = DateTime.Now;
                objAddGenCodeMasterViewModel.ModifiedById = 1;
                objAddGenCodeMasterViewModel.ModifiedDate = DateTime.Now;

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

                    Task <string> HttpPostResponse = null;

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

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

                    if (HttpPostResponse != null)
                    {
                        objAddGenCodeMasterViewModel = JsonConvert.DeserializeObject <AddGenCodeMasterViewModel>(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/GenCodeMaster/AddGenCodeMaster.cshtml", objAddGenCodeMasterViewModel));
                    }
                }
                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/GenCodeMaster/AddGenCodeMaster.cshtml", objAddGenCodeMasterViewModel));
                }
            }
            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());
        }