public IActionResult Create()
        {
            SaleFormModel model = new SaleFormModel
            {
                AllCustomers = this.customerService
                               .GetAllBasicCustomers()
                               .Select(c => new SelectListItem
                {
                    Value = c.Id.ToString(),
                    Text  = c.Name
                })
                               .ToList(),
                AllCars = this.carService
                          .GetAllBasicCars()
                          .Select(c => new SelectListItem
                {
                    Value = c.Id.ToString(),
                    Text  = $"{c.Make} {c.Model}"
                })
                          .ToList(),
                AllDiscounts = Enumerable.Range(0, 100)
                               .Select(n => new SelectListItem
                {
                    Value = n.ToString(),
                    Text  = n.ToString()
                })
                               .ToList()
            };

            return(View(model));
        }
        public IActionResult ReviewCreate(SaleFormModel model)
        {
            if (!this.customerService.Exists(model.CustomerId))
            {
                this.ModelState.AddModelError(nameof(model.CustomerId), "Invalid customer.");
            }

            if (!this.carService.Exists(model.CarId))
            {
                this.ModelState.AddModelError(nameof(model.CarId), "Invalid car.");
            }

            if (!this.ModelState.IsValid)
            {
                model.Cars      = this.GetCarsSelectList();
                model.Customers = this.GetCustomersSelectList();
                return(this.View(nameof(Create), model));
            }

            var customer = this.customerService.GetByIdWithAdditionalDiscount(model.CustomerId);
            var car      = this.carService.GetByIdWithPrice(model.CarId);

            var reviewModel = new SaleReviewModel
            {
                CustomerId         = model.CustomerId,
                CarId              = model.CarId,
                Discount           = model.Discount,
                Customer           = customer.Name,
                AdditionalDiscount = customer.AdditionalDiscount,
                Car   = car.MakeModel,
                Price = car.Price,
            };

            return(this.View(reviewModel));
        }
        public IActionResult FinalizeCreate(SaleReviewModel model)
        {
            if (!this.customerService.Exists(model.CustomerId))
            {
                this.ModelState.AddModelError(nameof(model.CustomerId), "Invalid customer.");
            }

            if (!this.carService.Exists(model.CarId))
            {
                this.ModelState.AddModelError(nameof(model.CarId), "Invalid car.");
            }

            if (!this.ModelState.IsValid)
            {
                var createModel = new SaleFormModel
                {
                    CarId      = model.CarId,
                    CustomerId = model.CustomerId,
                    Discount   = model.Discount,
                    Cars       = this.GetCarsSelectList(),
                    Customers  = this.GetCustomersSelectList()
                };
                return(this.View(nameof(Create), createModel));
            }

            this.saleService.Create(model.CustomerId, model.CarId, model.TotalDiscount);

            return(this.RedirectToAction(nameof(All)));
        }
 public IActionResult Create(SaleFormModel model)
 {
     if (!this.ModelState.IsValid)
     {
         model.AllCars      = this.GetCarListItems();
         model.AllCustomers = this.GetCustomerListItems();
         return(this.View(model));
     }
     return(this.RedirectToAction(nameof(this.Review), model));
 }
Esempio n. 5
0
        public IActionResult Add()
        {
            var model = new SaleFormModel
            {
                CarsDropdown      = this.cars.GetCarsSelectListItems(),
                CustomersDropdown = this.customers.GetCustomersSelectListItems()
            };

            return(View(model));
        }
Esempio n. 6
0
        public IActionResult Create()
        {
            var model = new SaleFormModel
            {
                CarsDropdown      = this.GetCarsSelectListItem(),
                CustomersDropdown = this.GetCustomersSelectListItem()
            };

            return(this.View(model));
        }
Esempio n. 7
0
        public IActionResult Create(SaleFormModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            //TODO: Redirect to Review Sale action(not created yet, it should be created here in SalesController)
            return(RedirectToAction(nameof(Details)));
        }
 public IActionResult Review(SaleFormModel model)
 => this.View(new ReviewFormModel
 {
     CustomerId    = model.CustomerId,
     IsYoungDriver = this.customers.ById(model.CustomerId).IsYoungDriver,
     CustomerName  = this.customers.ById(model.CustomerId).Name,
     CarId         = model.CarId,
     CarName       = this.cars.ById(model.CarId).MakeModel,
     Discount      = (model.Discount + (this.customers.ById(model.CustomerId).IsYoungDriver? 5:0)) / 100,
     CarPrice      = this.cars.ById(model.CarId).Price
 });
Esempio n. 9
0
        public IActionResult ReviewCreate(SaleFormModel saleModel)
        {
            if (!this.ModelState.IsValid)
            {
                saleModel.CarsDropdown      = this.GetCarsSelectListItem();
                saleModel.CustomersDropdown = this.GetCustomersSelectListItem();
                return(this.View(saleModel));
            }

            var saleReviewModel = this.saleService.SaleReview(
                saleModel.CarId,
                saleModel.CustomerId,
                saleModel.Discount);

            return(this.View(saleReviewModel));
        }
Esempio n. 10
0
        public IActionResult ReviewCreate(SaleFormModel saleModel)
        {
            if (!ModelState.IsValid)
            {
                saleModel.Cars      = this.GetCars();
                saleModel.Customers = this.GetCustomers();

                return(View(nameof(Create), saleModel));
            }

            SaleReviewModel saleReviewModel = this.sales.SaleReview(
                saleModel.CarId,
                saleModel.CustomerId,
                saleModel.Discount
                );

            return(View(saleReviewModel));
        }
Esempio n. 11
0
        public IActionResult ReviewSale(SaleFormModel model)
        {
            var car      = this.cars.ById(model.CarId);
            var customer = this.customers.ById(model.CustomerId);
            var discount = customer.IsYoungDriver ? 10.0 : 5.0;

            var review = new ReviewSaleViewModel
            {
                CarId         = customer.Id,
                CustomerId    = customer.Id,
                CustomerName  = customer.Name,
                Car           = car.Name,
                CarPrice      = car.Price,
                Discount      = discount,
                FinalCarPrice = car.Price * (100 - (decimal)discount) / 100
            };

            return(View(review));
        }
        public IActionResult Review(SaleFormModel saleModel)
        {
            CustomerBasicServiceModel customerModel = this.customerService.GetBasicCustomerById(saleModel.CustomerId);
            CarBasicServiceModel      carModel      = this.carService.GetBasicCarById(saleModel.CarId);

            SaleReviewFormModel model = new SaleReviewFormModel
            {
                CustomerId    = customerModel.Id,
                CustomerName  = customerModel.Name,
                IsYoungDriver = customerModel.IsYoungDriver,
                CarId         = carModel.Id,
                CarMake       = $"{carModel.Make} {carModel.Model}",
                Discount      = saleModel.Discount,
                CarPrice      = this.saleService.GetCarPrice(carModel.Id),
                FinalCarPrice = this.saleService.GetCarPriceWithDiscount(carModel.Id, saleModel.Discount, customerModel.IsYoungDriver)
            };

            return(View(model));
        }
Esempio n. 13
0
        public IActionResult FinalizeCreate(SaleReviewModel saleModel)
        {
            if (!this.ModelState.IsValid)
            {
                var createModel = new SaleFormModel
                {
                    CarsDropdown      = this.GetCarsSelectListItem(),
                    CustomersDropdown = this.GetCustomersSelectListItem()
                };
                return(this.RedirectToAction(nameof(Create), createModel));
            }

            this.saleService.Create(
                saleModel.CustomerId,
                saleModel.CarId,
                saleModel.Discount);

            return(this.RedirectToAction(nameof(All)));
        }
Esempio n. 14
0
        public IActionResult Add(SaleFormModel model)
        {
            if (!ModelState.IsValid)
            {
                View(new SaleFormModel
                {
                    Customers = this.Customers.AllCustomers().Select(c => new SelectListItem
                    {
                        Text  = c.Name,
                        Value = c.Id.ToString()
                    }),

                    Cars = this.Cars.AllCars().Select(c => new SelectListItem
                    {
                        Text  = c.Make + " " + c.Model,
                        Value = c.Id.ToString()
                    })
                });
            }
            this.Sales.Add(model.CarId, model.CustomerId, model.Discount);

            return(RedirectToAction(nameof(All)));
        }
Esempio n. 15
0
        public IActionResult FinalizeCreate(SaleReviewModel saleModel)
        {
            if (!ModelState.IsValid)
            {
                var createModel = new SaleFormModel
                {
                    Cars      = this.GetCars(),
                    Customers = this.GetCustomers(),
                };
                return(View(nameof(Create), createModel));
            }

            this.sales.CreateNewSale(
                saleModel.CarId,
                saleModel.CustomerId,
                saleModel.Discount
                );

            var userId = _userManager.GetUserId(HttpContext.User);

            this.logs.Add(userId, "Add", "Sale", DateTime.Now);

            return(RedirectToAction(nameof(AllSales)));
        }