public ActionResult Add(AddSaleBm bm) { if (this.ModelState.IsValid) { HttpPostedFileBase file = this.Request.Files["salePicture"]; if (file == null || !file.ContentType.Contains("image")) { this.ModelState.AddModelError("salePicture", "Invalid image"); } else { var pathToFolder = this.Server.MapPath("~/SalePictures"); string fileName = Path.GetFileName(file.FileName); string path = this.service.GetAdequatePathToSave(pathToFolder, fileName); file.SaveAs(path); var imageUrl = this.service.GetImageUrl(path); bm.Url = imageUrl; var userId = this.User.Identity.GetUserId(); this.service.AddSale(bm, userId); return(this.RedirectToAction("All")); } } AddSaleVm vm = Mapper.Map <AddSaleBm, AddSaleVm>(bm); return(this.View("Add", vm)); }
public void AddSale(AddSaleBm bm, string userId) { ApplicationUser currentUser = this.Context.Users.Find(userId); Sale sale = Mapper.Map <AddSaleBm, Sale>(bm); sale.PostDate = DateTime.Now; currentUser.Sales.Add(sale); this.Context.SaveChanges(); }
public ActionResult AddConfirmation(AddSaleBm addSaleBm) { var cookie = this.Request.Cookies.Get("sessionId"); if (cookie == null || !AuthenticationManager.IsAuthenticated(cookie.Value)) { return(this.RedirectToAction("Login", "Users")); } this.service.AddSale(addSaleBm); return(this.RedirectToAction("All", "Sales")); }
public ActionResult AddSales([Bind(Include = "CustomerId, CarId, Discount")] AddSaleBm addSaleBm) { if (this.ModelState.IsValid) { AddSaleConfirmationViewModel salesConfirmVm = this.service.GetConfirmatinModel(addSaleBm); return(this.RedirectToAction("AddConfirmation", salesConfirmVm)); } AddSalesViewModel addSalesVm = service.GenerateAddSalesForm(); return(this.View(addSalesVm)); }
public ActionResult Add([Bind(Include = "CustomerId, CarId, Discount")] AddSaleBm bind) { if (ModelState.IsValid) { AddSaleConfirmationVm confirmation = this.service.GetSaleConfirmattionVm(bind); return(RedirectToAction("AddConfirmation", confirmation)); } AddSaleVm addSaleVm = this.service.GetSaleVm(); return(this.View(addSaleVm)); }
public void AddSale(AddSaleBm addSaleBm) { Sale sale = new Sale(); Customer customer = Context.Customers.Find(addSaleBm.CustomerId); sale.Customer = customer; Car car = this.Context.Cars.Find(addSaleBm.CarId); sale.Car = car; sale.Discount = addSaleBm.Discount / 100.0; this.Context.Sales.Add(sale); this.Context.SaveChanges(); }
public void AddSale(AddSaleBm vm) { Car carModel = this.Context.Cars.Find(vm.CarId); Customer customerModel = this.Context.Customers.Find(vm.CustomerId); Sale sale = new Sale() { Customer = customerModel, Car = carModel, Discount = vm.Discount / 100.0 }; this.Context.Sales.Add(sale); this.Context.SaveChanges(); }
public void AddSale(AddSaleBm bind) { Car car = this.Context.Cars.Find(bind.CarId); Customer customer = this.Context.Customers.Find(bind.CustomerId); Sale sale = new Sale() { Car = car, Customer = customer, Discount = bind.Discount / 100 }; this.Context.Sales.Add(sale); this.Context.SaveChanges(); }
public AddSaleConfirmationVm GetSaleCofirmationVm(AddSaleBm bind) { Car carModel = this.Context.Cars.Find(bind.CarId); Customer customerModel = this.Context.Customers.Find(bind.CustomerId); AddSaleConfirmationVm vm = new AddSaleConfirmationVm() { Discount = bind.Discount, CarPrice = (decimal)carModel.Parts.Sum(part => part.Price).Value, CarId = carModel.Id, CarRepresentation = $"{carModel.Make} {carModel.Model}", CustomerId = customerModel.Id, CustomerName = customerModel.Name }; vm.Discount += customerModel.IsYoungDriver ? 5 : 0; vm.FinalCarPrice = vm.CarPrice - vm.CarPrice * vm.Discount / 100; return(vm); }
public SaleReviewVm GetSaleReviewVm(AddSaleBm model) { var viewModel = new SaleReviewVm(); var car = this.context.Cars.Find(model.CarId); var customer = this.context.Customers.Find(model.CustomerId); viewModel.CarId = car.Id; viewModel.CustomerId = customer.Id; viewModel.CustomerName = customer.Name; viewModel.CarName = car.Make + " " + car.Model; viewModel.CarPrice = car.Parts.Sum(x => x.Price); viewModel.IsYoungDriver = customer.IsYoungDriver; viewModel.Discount = model.Discount; viewModel.Discount += customer.IsYoungDriver ? 5 : 0; viewModel.FinalCarPrice = viewModel.CarPrice / (1 + (viewModel.Discount / 100)); return(viewModel); }
public AddSaleConfirmationVm GetSaleConfirmattionVm(AddSaleBm bind) { Car car = this.Context.Cars.Find(bind.CarId); Customer customer = this.Context.Customers.Find(bind.CustomerId); AddSaleConfirmationVm vm = new AddSaleConfirmationVm() { Discount = bind.Discount, CarId = car.Id, CarPrice = (double)car.Parts.Sum(a => a.Price), CustomerId = customer.Id, CustomerName = customer.Name, CarRepresentation = car.Make + " " + car.Model, }; vm.Discount += customer.IsYoungDriver ? 5 : 0; vm.FinalCarPrice = vm.CarPrice + vm.Discount / 100.0; return(vm); }
public AddSaleConfirmationViewModel GetConfirmatinModel(AddSaleBm addSaleBm) { AddSaleConfirmationViewModel confVm = new AddSaleConfirmationViewModel(); confVm.CarId = addSaleBm.CarId; confVm.CustomerId = addSaleBm.CustomerId; Customer customer = this.Context.Customers.Find(confVm.CustomerId); Car car = this.Context.Cars.Find(confVm.CarId); if (customer.IsYoungDriver) { confVm.TotalDiscount = 5 + addSaleBm.Discount; } confVm.CustomerName = customer.Name; confVm.TotalDiscount = addSaleBm.Discount; confVm.CarName = car.Make + " " + car.Model; confVm.CarPrice = (decimal)car.Parts.Sum(p => p.Price).Value; confVm.FinalCarPrice = confVm.CarPrice - confVm.CarPrice * confVm.TotalDiscount / 100; return(confVm); }
public ActionResult Add([Bind(Include = "CustomerId, CarId, Discount")] AddSaleBm model) { var httpCookie = this.Request.Cookies.Get("sessionId"); if (httpCookie == null || !AuthenticationManager.IsAuthenticated(httpCookie.Value)) { return(this.RedirectToAction("Login", "Users")); } var user = AuthenticationManager.GetUser(httpCookie.Value); ViewBag.Username = user.Username; if (this.ModelState.IsValid) { var saleReviewVm = this.service.GetSaleReviewVm(model); return(this.RedirectToAction("Review", saleReviewVm)); } var viewModel = this.service.GetAddSaleVm(); return(this.View(viewModel)); }