public void FinalizeSale(AddSaleBindingModel asbm)
        {
            Sale saleEntity = Mapper.Map <Sale>(asbm);

            this.DbContext.Sales.Add(saleEntity);
            this.DbContext.SaveChanges();
        }
Example #2
0
        public ActionResult Finalize(AddSaleBindingModel sale)
        {
            if (!UserInfo.IsLogged)
            {
                return(this.RedirectToAction("Login", "Users"));
            }
            this.saleService.AddSale(sale);

            return(this.RedirectToAction("Sales", "Sales"));
        }
Example #3
0
        public ActionResult Add([Bind(Include = "CustomerId, CarId, Discount")] AddSaleBindingModel bind)
        {
            if (ModelState.IsValid)
            {
                AddSalesConfirmationViewModel confirmationVm = this.service.GetSalesConfirmationViewModel(bind);
                return(RedirectToAction("AddConfirmation", confirmationVm));
            }
            AddSaleViewModel vm = this.service.GetSalesViewModel();

            return(View(vm));
        }
Example #4
0
        public ActionResult AddConfirmation(AddSaleBindingModel bind)
        {
            var cookie = this.Request.Cookies.Get("sessionId");

            if (cookie == null || !AuthenticatedManager.IsAuthenticated(cookie.Value))
            {
                return(this.RedirectToAction("Login", "Users"));
            }
            this.service.AddSale(bind);
            return(this.RedirectToAction("All"));
        }
Example #5
0
        public void AddSale(AddSaleBindingModel sale)
        {
            var newSale = new Sale()
            {
                CustomerId = sale.CustomerId,
                CarId      = sale.CarId,
                Discount   = sale.Discount
            };

            this.sales.Add(newSale);
            this.sales.SaveChanges();
        }
Example #6
0
        public ActionResult Add(AddSaleBindingModel saleDetails)
        {
            if (!UserInfo.IsLogged)
            {
                return(this.RedirectToAction("Login", "Users"));
            }

            var customer = this.customersService.GetCustomerById(saleDetails.CustomerId);
            var car      = this.carsService.GetCarById(saleDetails.CarId);

            var reviewSaleVm = this.saleService.GetReviewSaleVm(customer, car, saleDetails);

            return(this.View("~/Views/Sales/ReviewSale.cshtml", reviewSaleVm));
        }
Example #7
0
        public void AddSale(AddSaleBindingModel bind)
        {
            Car      carModel      = this.Context.Cars.Find(bind.CarId);
            Customer customerModel = this.Context.Customers.Find(bind.CustomerId);

            Sale sale = new Sale()
            {
                Customer = customerModel,
                Car      = carModel,
                Discount = bind.Discount / 100
            };

            this.Context.Sales.Add(sale);
            this.Context.SaveChanges();
        }
Example #8
0
        public ReviewSaleViewModel GetReviewSaleVm(Customer customer, Car car, AddSaleBindingModel saleDetails)
        {
            var carPrice = car.Parts.Where(p => p.Price != null).Sum(p => (double)p.Price);

            var reviewSaleVm = new ReviewSaleViewModel()
            {
                Customer   = customer.Name,
                CustomerId = saleDetails.CustomerId,
                Car        = $"{car.Make} {car.Model}",
                CarId      = saleDetails.CarId,
                Discount   = saleDetails.Discount,
                CarPrice   = carPrice,
                FinalPrice = carPrice * (1 - saleDetails.Discount)
            };

            return(reviewSaleVm);
        }
Example #9
0
        public AddSalesConfirmationViewModel GetSalesConfirmationViewModel(AddSaleBindingModel bind)
        {
            Car      carModel                = this.Context.Cars.Find(bind.CarId);
            Customer customerModel           = this.Context.Customers.Find(bind.CustomerId);
            AddSalesConfirmationViewModel vm = new AddSalesConfirmationViewModel()
            {
                Discount          = bind.Discount,
                CustomerId        = customerModel.Id,
                CarId             = carModel.Id,
                CarPrice          = (decimal)carModel.Parts.Sum(p => p.Price).Value,
                CarRepresentation = $"{carModel.Make} {carModel.Model}"
            };

            vm.Discount      += customerModel.IsYoungDriver ? 5 : 0;
            vm.FinalCarPrice += vm.CarPrice - vm.CarPrice * vm.Discount / 100;
            return(vm);
        }
        public ReviewSaleViewModel GetReviewSaleViewModel(AddSaleBindingModel asbm)
        {
            Car      carEntity      = this.DbContext.Cars.Find(asbm.CarId);
            Customer customerEntity = this.DbContext.Customers.Find(asbm.CustomerId);

            ReviewSaleViewModel reviewViewModel = new ReviewSaleViewModel()
            {
                Car                   = Mapper.Map <AddSaleCarViewModel>(carEntity),
                Customer              = Mapper.Map <AddSaleCustomerViewModel>(customerEntity),
                CarDisplay            = carEntity.Make + " " + carEntity.Model,
                Discount              = asbm.Discount,
                HasAdditionalDiscount = customerEntity.IsYoungDriver,
                CarPrice              = carEntity.Parts.Sum(part => part.Price),
                FinalCarPrice         = customerEntity.IsYoungDriver
                    ? carEntity.Parts.Sum(p => p.Price) - ((asbm.Discount + 5) / 100) * carEntity.Parts.Sum(p => p.Price)
                    : carEntity.Parts.Sum(p => p.Price) - (asbm.Discount / 100) * carEntity.Parts.Sum(p => p.Price)
            };

            return(reviewViewModel);
        }
Example #11
0
 public ActionResult FinalizeSale([Bind(Include = "CarId,CustomerId,Discount")] AddSaleBindingModel asbm)
 {
     this.service.FinalizeSale(asbm);
     return(RedirectToAction("All"));
 }
Example #12
0
        public ActionResult Review([Bind(Include = "CustomerId,CarId,Discount")] AddSaleBindingModel bindingModel)
        {
            ReviewSaleViewModel reviewVm = this.service.GetReviewSaleViewModel(bindingModel);

            return(this.View(reviewVm));
        }