Exemplo n.º 1
0
        public ActionResult ChangeDiscount(int id, int?maxDiscount, int?stepDiscount)
        {
            var customer          = _managerService.GetCustomerById(id);
            var customerViewModel = MappingViewModel.MapCustomerViewModel(customer);

            if (Request.HttpMethod == "POST")
            {
                if (maxDiscount == null)
                {
                    ModelState.AddModelError("maxDiscount", "Please enter max discount");
                }
                if (stepDiscount == null)
                {
                    ModelState.AddModelError("stepDiscount", "Please enter step discount");
                }
                if (ModelState.IsValid)
                {
                    customer.StepDiscount = stepDiscount.Value;
                    customer.MaxDiscount  = maxDiscount.Value;
                    _managerService.ChangeDiscountCustomer(customer);
                    SLogger.InfoToFile($"Manager change discount customer id: {customer.Id}");
                    var messageInfo = new MessageViewModel()
                    {
                        Status = "success",
                        Info   = $"Changed discount for {customer.Name}"
                    };
                    return(RedirectToAction("Index", messageInfo));
                }
                else
                {
                    return(View(customerViewModel));
                }
            }
            else
            {
                return(View(customerViewModel));
            }
        }