示例#1
0
        public IActionResult ViewLicence()
        {
            try
            {
                ViewLicenceAggrementViewModel objViewLicenceAggrementViewModel = null;
                string        endpoint        = apiBaseUrl + "MasterCompanies/1";
                Task <string> HttpGetResponse = CommonFunction.GetWebAPI(endpoint);

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

                DropDownFillMethod();
                objViewLicenceAggrementViewModel.Mode = CommonFunction.Mode.UPDATE;
                return(View("~/Views/Administrator/LicenceAggrement/ViewLicence.cshtml", objViewLicenceAggrementViewModel));
            }
            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 SaveLicence(ViewLicenceAggrementViewModel objViewLicenceAggrementViewModel, IFormFile _CompanyLogo)
        {
            try
            {
                //for main image Logo
                if (_CompanyLogo != null)
                {
                    objViewLicenceAggrementViewModel.CompanyLogo = UploadedImageFile(_CompanyLogo, objViewLicenceAggrementViewModel.CompanyLogo);
                }

                objViewLicenceAggrementViewModel.EnterById           = CommonFunction.UserAuthentication(this.HttpContext);
                objViewLicenceAggrementViewModel.EnterDate           = DateTime.Now;
                objViewLicenceAggrementViewModel.ModifiedById        = CommonFunction.UserAuthentication(this.HttpContext);
                objViewLicenceAggrementViewModel.ModifiedDate        = DateTime.Now;
                objViewLicenceAggrementViewModel.MasterAddressTypeId = 1;
                objViewLicenceAggrementViewModel.IsActive            = true;

                if (objViewLicenceAggrementViewModel.MasterAddressTypeId == null)
                {
                    objViewLicenceAggrementViewModel.MasterAddressTypeId = 2;
                }

                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 + "MasterCompanies";

                    Task <string> HttpPostResponse = null;

                    if (objViewLicenceAggrementViewModel.Mode == CommonFunction.Mode.UPDATE)
                    {
                        endpoint         = apiBaseUrl + "MasterCompanies/" + objViewLicenceAggrementViewModel.MasterCompanyId;
                        HttpPostResponse = CommonFunction.PutWebAPI(endpoint, objViewLicenceAggrementViewModel);

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

                    if (HttpPostResponse != null)
                    {
                        objViewLicenceAggrementViewModel = JsonConvert.DeserializeObject <ViewLicenceAggrementViewModel>(HttpPostResponse.Result);
                        _logger.LogInformation("Database Insert/Update: ");//+ JsonConvert.SerializeObject(objAddGenCodeTypeViewModel)); ;
                        return(RedirectToAction("ViewLicence"));
                    }
                    else
                    {
                        DropDownFillMethod();
                        ModelState.Clear();
                        ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                        return(View("~/Views/Administrator/LicenceAggrement/ViewLicence.cshtml", objViewLicenceAggrementViewModel));
                    }
                }
                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/Administrator/LicenceAggrement/ViewLicence.cshtml", objViewLicenceAggrementViewModel));
                }
            }
            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());
        }