Esempio n. 1
0
        public IActionResult AddMasterTypeOfDevice()
        {
            try
            {
                AddMasterTypeOfDeviceViewModel objAddMasterTypeOfDeviceViewModel = new AddMasterTypeOfDeviceViewModel();
                objAddMasterTypeOfDeviceViewModel.Mode                 = CommonFunction.Mode.SAVE;
                objAddMasterTypeOfDeviceViewModel.IsActive             = true;
                objAddMasterTypeOfDeviceViewModel.MasterTypeOfDeviceId = CommonFunction.NextMasterId("ADMasterTypeOfDevice", apiBaseUrl);
                objAddMasterTypeOfDeviceViewModel.MasterTypeOfDeviceId = 0;
                objAddMasterTypeOfDeviceViewModel.TypeOfDeviceTitle    = "";
                objAddMasterTypeOfDeviceViewModel.TypeOfDeviceName     = "";
                //DropDownFillMethod();

                //Return View doesn't make a new requests, it just renders the view
                return(View("~/Views/Master/MasterTypeOfDevice/AddMasterTypeOfDevice.cshtml", objAddMasterTypeOfDeviceViewModel));
            }
            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());
        }
Esempio n. 2
0
        public IActionResult ViewMasterTypeOfDevice(long MasterTypeOfDeviceId)
        {
            try
            {
                AddMasterTypeOfDeviceViewModel objAddMasterTypeOfDeviceViewModel = null;
                string        endpoint        = apiBaseUrl + "MasterTypeOfDevices/" + MasterTypeOfDeviceId;
                Task <string> HttpGetResponse = CommonFunction.GetWebAPI(endpoint);

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

                //DropDownFillMethod();
                objAddMasterTypeOfDeviceViewModel.Mode = CommonFunction.Mode.UPDATE;
                return(View("~/Views/Master/MasterTypeOfDevice/AddMasterTypeOfDevice.cshtml", objAddMasterTypeOfDeviceViewModel));
            }
            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());
        }
Esempio n. 3
0
        public IActionResult SaveMasterTypeOfDevice(AddMasterTypeOfDeviceViewModel objAddMasterTypeOfDeviceViewModel)
        {
            try
            {
                objAddMasterTypeOfDeviceViewModel.EnterById    = 1;
                objAddMasterTypeOfDeviceViewModel.EnterDate    = DateTime.Now;
                objAddMasterTypeOfDeviceViewModel.ModifiedById = 1;
                objAddMasterTypeOfDeviceViewModel.ModifiedDate = DateTime.Now;

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

                    Task <string> HttpPostResponse = null;

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

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

                    if (HttpPostResponse != null)
                    {
                        objAddMasterTypeOfDeviceViewModel = JsonConvert.DeserializeObject <AddMasterTypeOfDeviceViewModel>(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/MasterTypeOfDevice/AddMasterTypeOfDevice.cshtml", objAddMasterTypeOfDeviceViewModel));
                    }
                }
                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/MasterTypeOfDevice/AddMasterTypeOfDevice.cshtml", objAddMasterTypeOfDeviceViewModel));
                }
            }
            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());
        }