Esempio n. 1
0
        public IActionResult AddMasterCurrency()
        {
            try
            {
                AddMasterCurrencyViewModel objAddMasterCurrencyViewModel = new AddMasterCurrencyViewModel();
                objAddMasterCurrencyViewModel.Mode             = CommonFunction.Mode.SAVE;
                objAddMasterCurrencyViewModel.IsActive         = true;
                objAddMasterCurrencyViewModel.MasterCurrencyId = CommonFunction.NextMasterId("ADMasterCurrency", apiBaseUrl);
                objAddMasterCurrencyViewModel.MasterCurrencyId = 0;
                objAddMasterCurrencyViewModel.CurrencyTitle    = "";
                objAddMasterCurrencyViewModel.CurrencySymbol   = "";
                objAddMasterCurrencyViewModel.MasterCountryId  = 1;
                DropDownFillMethod();

                //Return View doesn't make a new requests, it just renders the view
                return(View("~/Views/Master/MasterCurrency/AddMasterCurrency.cshtml", objAddMasterCurrencyViewModel));
            }
            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 ViewMasterCurrency(long MasterCurrencyId)
        {
            try
            {
                AddMasterCurrencyViewModel objAddMasterCurrencyViewModel = null;
                string        endpoint        = apiBaseUrl + "MasterCurrencies/" + MasterCurrencyId;
                Task <string> HttpGetResponse = CommonFunction.GetWebAPI(endpoint);

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

                DropDownFillMethod();
                objAddMasterCurrencyViewModel.Mode = CommonFunction.Mode.UPDATE;
                return(View("~/Views/Master/MasterCurrency/AddMasterCurrency.cshtml", objAddMasterCurrencyViewModel));
            }
            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 SaveMasterCurrency(AddMasterCurrencyViewModel objAddMasterCurrencyViewModel)
        {
            try
            {
                objAddMasterCurrencyViewModel.EnterById    = 1;
                objAddMasterCurrencyViewModel.EnterDate    = DateTime.Now;
                objAddMasterCurrencyViewModel.ModifiedById = 1;
                objAddMasterCurrencyViewModel.ModifiedDate = DateTime.Now;

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

                    Task <string> HttpPostResponse = null;

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

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

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