Beispiel #1
0
        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));
        }
Beispiel #2
0
        public AddSaleVm GetSaleVm()
        {
            AddSaleVm              vm        = new AddSaleVm();
            IEnumerable <Car>      cars      = this.Context.Cars;
            IEnumerable <Customer> customers = this.Context.Customers;

            IEnumerable <AddSaleCarVm> viewCars =
                Mapper.Map <IEnumerable <Car>, IEnumerable <AddSaleCarVm> >(cars);
            IEnumerable <AddSaleCustomerVm> viewCustomers =
                Mapper.Map <IEnumerable <Customer>, IEnumerable <AddSaleCustomerVm> >(customers);

            List <int> discounts = new List <int>();

            for (int i = 0; i <= 50; i += 5)
            {
                discounts.Add(i);
            }

            vm.Cars      = viewCars.OrderBy(a => a.Make).ThenBy(b => b.Model);
            vm.Customers = viewCustomers.OrderBy(b => b.Name);
            vm.Discounts = discounts;


            return(vm);
        }
Beispiel #3
0
        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));
        }
Beispiel #4
0
        public ActionResult Add()
        {
            var cookie = this.Request.Cookies.Get("sessionId");

            if (cookie == null || !AuthenticationManager.IsAuthenticated(cookie.Value))
            {
                return(this.RedirectToAction("Login", "User"));
            }
            AddSaleVm vm = this.service.GetSaleVm();

            return(View(vm));
        }
Beispiel #5
0
        public AddSaleVm GetAddSaleVm()
        {
            var viewModel = new AddSaleVm();

            var customers = this.context.Customers.ToList();

            var cars = this.context.Cars.ToList();

            List <int> discounts = new List <int>();

            for (int i = 0; i < 50; i += 5)
            {
                discounts.Add(i);
            }

            viewModel.Customers = customers;
            viewModel.Cars      = cars;
            viewModel.Discounts = discounts;

            return(viewModel);
        }
Beispiel #6
0
        public AddSaleVm GetSalesVm()
        {
            AddSaleVm              vm             = new AddSaleVm();
            IEnumerable <Car>      carModels      = this.Context.Cars;
            IEnumerable <Customer> customerModels = this.Context.Customers;

            IEnumerable <AddSaleCarVm>      carVms      = Mapper.Map <IEnumerable <Car>, IEnumerable <AddSaleCarVm> >(carModels);
            IEnumerable <AddSaleCustomerVm> customerVms =
                Mapper.Map <IEnumerable <Customer>, IEnumerable <AddSaleCustomerVm> >(customerModels);

            List <int> discounts = new List <int>();

            for (int i = 0; i <= 50; i += 5)
            {
                discounts.Add(i);
            }

            vm.Cars      = carVms;
            vm.Customers = customerVms;
            vm.Discounts = discounts;

            return(vm);
        }