コード例 #1
0
        public IActionResult AddMasterRegistrationType()
        {
            try
            {
                AddMasterRegistrationTypeViewModel objAddMasterRegistrationTypeViewModel = new AddMasterRegistrationTypeViewModel();
                objAddMasterRegistrationTypeViewModel.Mode     = CommonFunction.Mode.SAVE;
                objAddMasterRegistrationTypeViewModel.IsActive = true;
                objAddMasterRegistrationTypeViewModel.MasterRegistrationTypeId     = CommonFunction.NextMasterId("ADMasterRegistrationType", apiBaseUrl);
                objAddMasterRegistrationTypeViewModel.MasterRegistrationTypeId     = 0;
                objAddMasterRegistrationTypeViewModel.MasterRegistrationTypeTitle  = "";
                objAddMasterRegistrationTypeViewModel.MasterRegistrationCode       = "";
                objAddMasterRegistrationTypeViewModel.MasterRegistrationExpertType = "";
                //DropDownFillMethod();

                //Return View doesn't make a new requests, it just renders the view
                return(View("~/Views/Master/MasterRegistrationType/AddMasterRegistrationType.cshtml", objAddMasterRegistrationTypeViewModel));
            }
            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());
        }
コード例 #2
0
        public IActionResult ViewMasterRegistrationType(long MasterRegistrationTypeId)
        {
            try
            {
                AddMasterRegistrationTypeViewModel objAddMasterRegistrationTypeViewModel = null;
                string        endpoint        = apiBaseUrl + "MasterRegistrationTypes/" + MasterRegistrationTypeId;
                Task <string> HttpGetResponse = CommonFunction.GetWebAPI(endpoint);

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

                //DropDownFillMethod();
                objAddMasterRegistrationTypeViewModel.Mode = CommonFunction.Mode.UPDATE;
                return(View("~/Views/Master/MasterRegistrationType/AddMasterRegistrationType.cshtml", objAddMasterRegistrationTypeViewModel));
            }
            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());
        }
コード例 #3
0
        public IActionResult SaveMasterRegistrationType(AddMasterRegistrationTypeViewModel objAddMasterRegistrationTypeViewModel)
        {
            try
            {
                objAddMasterRegistrationTypeViewModel.EnterById    = 1;
                objAddMasterRegistrationTypeViewModel.EnterDate    = DateTime.Now;
                objAddMasterRegistrationTypeViewModel.ModifiedById = 1;
                objAddMasterRegistrationTypeViewModel.ModifiedDate = DateTime.Now;

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

                    Task <string> HttpPostResponse = null;

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

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

                    if (HttpPostResponse != null)
                    {
                        objAddMasterRegistrationTypeViewModel = JsonConvert.DeserializeObject <AddMasterRegistrationTypeViewModel>(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/MasterRegistrationType/AddMasterRegistrationType.cshtml", objAddMasterRegistrationTypeViewModel));
                    }
                }
                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/MasterRegistrationType/AddMasterRegistrationType.cshtml", objAddMasterRegistrationTypeViewModel));
                }
            }
            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());
        }