public IActionResult AddMasterSalutation() { try { AddMasterSalutationViewModel objAddMasterSalutationViewModel = new AddMasterSalutationViewModel(); objAddMasterSalutationViewModel.Mode = CommonFunction.Mode.SAVE; objAddMasterSalutationViewModel.IsActive = true; objAddMasterSalutationViewModel.MasterSalutationId = CommonFunction.NextMasterId("ADMasterSalutations", apiBaseUrl); objAddMasterSalutationViewModel.MasterSalutationId = 0; objAddMasterSalutationViewModel.SalutationTitle = ""; objAddMasterSalutationViewModel.SalutationCode = ""; objAddMasterSalutationViewModel.EnterById = 0; objAddMasterSalutationViewModel.EnterDate = DateTime.Now; DropDownFillMethod(); //Return View doesn't make a new requests, it just renders the view return(View("~/Views/Master/MasterSalutation/AddMasterSalutation.cshtml", objAddMasterSalutationViewModel)); } 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 ViewMasterSalutation(long MasterSalutationId) { try { AddMasterSalutationViewModel objAddMasterSalutationViewModel = null; string endpoint = apiBaseUrl + "MasterSalutations/" + MasterSalutationId; Task <string> HttpGetResponse = CommonFunction.GetWebAPI(endpoint); if (HttpGetResponse != null) { objAddMasterSalutationViewModel = JsonConvert.DeserializeObject <AddMasterSalutationViewModel>(HttpGetResponse.Result); } else { objAddMasterSalutationViewModel = new AddMasterSalutationViewModel(); ModelState.AddModelError(string.Empty, "Server error. Please contact administrator."); } DropDownFillMethod(); objAddMasterSalutationViewModel.Mode = CommonFunction.Mode.UPDATE; return(View("~/Views/Master/MasterSalutation/AddMasterSalutation.cshtml", objAddMasterSalutationViewModel)); } 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 SaveMasterSalutation(AddMasterSalutationViewModel objAddMasterSalutationViewModel) { try { objAddMasterSalutationViewModel.EnterById = 1; objAddMasterSalutationViewModel.EnterDate = DateTime.Now; objAddMasterSalutationViewModel.ModifiedById = 1; objAddMasterSalutationViewModel.ModifiedDate = DateTime.Now; if (objAddMasterSalutationViewModel.IsActive == null) { objAddMasterSalutationViewModel.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 + "MasterSalutations"; Task <string> HttpPostResponse = null; if (objAddMasterSalutationViewModel.Mode == CommonFunction.Mode.SAVE) { HttpPostResponse = CommonFunction.PostWebAPI(endpoint, objAddMasterSalutationViewModel); //Notification Message //Session is used to store object HttpContext.Session.SetObjectAsJson("GlobalMessage", CommonFunction.GlobalMessage(1, 2, 4, "Master Salutation", "Master Salutation Insert Successfully!", "")); } else if (objAddMasterSalutationViewModel.Mode == CommonFunction.Mode.UPDATE) { endpoint = apiBaseUrl + "MasterSalutations/" + objAddMasterSalutationViewModel.MasterSalutationId; HttpPostResponse = CommonFunction.PutWebAPI(endpoint, objAddMasterSalutationViewModel); //Notification Message //Session is used to store object HttpContext.Session.SetObjectAsJson("GlobalMessage", CommonFunction.GlobalMessage(1, 2, 4, "Master Salutation", "Master Salutation Update Successfully!", "")); } if (HttpPostResponse != null) { objAddMasterSalutationViewModel = JsonConvert.DeserializeObject <AddMasterSalutationViewModel>(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/MasterSalutation/AddMasterSalutation.cshtml", objAddMasterSalutationViewModel)); } } 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/MasterSalutation/AddMasterSalutation.cshtml", objAddMasterSalutationViewModel)); } } 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()); }