public IActionResult AddMasterBranch() { try { AddMasterBranchViewModel objAddMasterBranchViewModel = new AddMasterBranchViewModel(); objAddMasterBranchViewModel.Mode = CommonFunction.Mode.SAVE; objAddMasterBranchViewModel.IsActive = true; objAddMasterBranchViewModel.MasterBranchId = CommonFunction.NextMasterId("ADMasterBranch", apiBaseUrl); objAddMasterBranchViewModel.MasterBranchId = 0; objAddMasterBranchViewModel.DateofRegistration = DateTime.Now; objAddMasterBranchViewModel.MasterAddressTypeId = 1; objAddMasterBranchViewModel.MasterCompanyId = 1; objAddMasterBranchViewModel.MasterCountryId = 101; DropDownFillMethod(); objAddMasterBranchViewModel.ProductDetailResultList = new List <ProductDetailResult>(); //Return View doesn't make a new requests, it just renders the view return(View("~/Views/Master/MasterBranch/AddMasterBranch.cshtml", objAddMasterBranchViewModel)); } 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 ViewMasterBranch(long MasterBranchId) { try { AddMasterBranchViewModel objAddMasterBranchViewModel = null; string endpoint = apiBaseUrl + "MasterBranches/" + MasterBranchId; Task <string> HttpGetResponse = CommonFunction.GetWebAPI(endpoint); if (HttpGetResponse != null) { objAddMasterBranchViewModel = JsonConvert.DeserializeObject <AddMasterBranchViewModel>(HttpGetResponse.Result); } else { objAddMasterBranchViewModel = new AddMasterBranchViewModel(); ModelState.AddModelError(string.Empty, "Server error. Please contact administrator."); } DropDownFillMethod(); objAddMasterBranchViewModel.Mode = CommonFunction.Mode.UPDATE; DashboardAdminViewModel objDashboardAdminViewModel = null; endpoint = assetsApiBaseUrl + "Dashboard?MasterSubCategoryId=0&MasterBranchId=" + MasterBranchId; Task <string> HttpGetResponseProduct = CommonFunction.GetWebAPI(endpoint); if (HttpGetResponse != null) { objDashboardAdminViewModel = JsonConvert.DeserializeObject <DashboardAdminViewModel>(HttpGetResponseProduct.Result); } else { objDashboardAdminViewModel = new DashboardAdminViewModel();; ModelState.AddModelError(string.Empty, "Server error. Please contact administrator."); } objAddMasterBranchViewModel.ProductDetailResultList = objDashboardAdminViewModel.AssetsSubCategoryList.ToList(); return(View("~/Views/Master/MasterBranch/AddMasterBranch.cshtml", objAddMasterBranchViewModel)); } 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 SaveMasterBranch(AddMasterBranchViewModel objAddMasterBranchViewModel) { try { objAddMasterBranchViewModel.EnterById = 1; objAddMasterBranchViewModel.EnterDate = DateTime.Now; objAddMasterBranchViewModel.ModifiedById = 1; objAddMasterBranchViewModel.ModifiedDate = DateTime.Now; if (objAddMasterBranchViewModel.IsActive == null) { objAddMasterBranchViewModel.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 + "MasterBranches"; Task <string> HttpPostResponse = null; if (objAddMasterBranchViewModel.Mode == CommonFunction.Mode.SAVE) { HttpPostResponse = CommonFunction.PostWebAPI(endpoint, objAddMasterBranchViewModel); //Notification Message //Session is used to store object HttpContext.Session.SetObjectAsJson("GlobalMessage", CommonFunction.GlobalMessage(1, 2, 4, "Master Branch", "Master Branch Insert Successfully!", "")); } else if (objAddMasterBranchViewModel.Mode == CommonFunction.Mode.UPDATE) { endpoint = apiBaseUrl + "MasterBranches/" + objAddMasterBranchViewModel.MasterBranchId; HttpPostResponse = CommonFunction.PutWebAPI(endpoint, objAddMasterBranchViewModel); //Notification Message //Session is used to store object HttpContext.Session.SetObjectAsJson("GlobalMessage", CommonFunction.GlobalMessage(1, 2, 4, "Master Branch", "Master Branch Update Successfully!", "")); } if (HttpPostResponse != null) { objAddMasterBranchViewModel = JsonConvert.DeserializeObject <AddMasterBranchViewModel>(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/MasterBranch/AddMasterBranch.cshtml", objAddMasterBranchViewModel)); } } 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/MasterBranch/AddMasterBranch.cshtml", objAddMasterBranchViewModel)); } } 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()); }