コード例 #1
0
        public async Task <ActionResult <SaleResultAddViewModel> > AddSale(AddSaleViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var sale = _mapper.Map <Sale>(model);

            var newSale = await _saleRepository.AddSale(sale);

            if (newSale == null)
            {
                return(BadRequest());
            }
            try
            {
                var newSaleResult = _mapper.Map <SaleResultAddViewModel>(newSale);
                return(CreatedAtAction(nameof(AddSale), new { id = newSaleResult.IdSale }, newSaleResult));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #2
0
        public AddSalePage()
        {
            var vm = new AddSaleViewModel();

            vm.Navigation  = Navigation;
            BindingContext = vm;
            InitializeComponent();
        }
コード例 #3
0
 public SelectProductPage(AddSaleViewModel parent) : base()
 {
     InitializeComponent();
     ParentVM                      = parent;
     SelectedProducts              = ParentVM.SelectedProducts;
     ProductService                = DependencyService.Get <IProductService>();
     SearchProductBar.TextChanged += SearchProductBar_TextChanged;
     GetProducts();
 }
コード例 #4
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));
        }
コード例 #5
0
        public IActionResult AddSale(AddSaleViewModel model)
        {
            var sale = new Sale()
            {
                Name            = model.Name,
                PercentOffPrice = model.PercentOff
            };

            this.Db.Sales.Add(sale);
            this.Db.SaveChanges();
            return(RedirectToAction("Sales", "AdministratorSales"));
        }
コード例 #6
0
        public ActionResult Add()
        {
            var cookie = this.Request.Cookies.Get("sessionId");

            if (cookie == null || !AuthenticatedManager.IsAuthenticated(cookie.Value))
            {
                return(this.RedirectToAction("Login", "Users"));
            }
            AddSaleViewModel vm = this.service.GetSalesViewModel();

            return(View(vm));
        }
コード例 #7
0
        public async Task <AddSaleViewModel> GetViewModelForCreateSale(int countryId)
        {
            var viewModel = new AddSaleViewModel
            {
                CountryId = countryId,
            };

            viewModel.CitiesItems = await this.citiesService.GetAllAsKeyValuePairsAsync(viewModel.CountryId);

            viewModel.Car = await this.carsService.GetCarInputModelWithFilledListItems();

            return(viewModel);
        }
コード例 #8
0
        public AddSaleViewModel GetAddSalesVm(IQueryable <Customer> customers, IQueryable <Car> cars)
        {
            var addSalesVm = new AddSaleViewModel()
            {
                Car = cars.Select(c => new SelectListItem {
                    Text = c.Make + " " + c.Model, Value = c.Id.ToString()
                }),
                Customer = customers.Select(c => new SelectListItem {
                    Text = c.Name, Value = c.Id.ToString()
                }),
                Discount = this.GetAllDiscounts().Select(d => new SelectListItem {
                    Text = d.ToString(CultureInfo.InvariantCulture), Value = d.ToString(CultureInfo.InvariantCulture)
                })
            };

            return(addSalesVm);
        }
コード例 #9
0
        public async Task <int> CreateSaleAsync(AddSaleViewModel input, string userId)
        {
            var saleToAdd = new Sale
            {
                CityId           = input.CityId,
                DaysValid        = input.DaysValid,
                Price            = input.Price,
                CountryId        = input.CountryId,
                Description      = input.Description,
                Car              = this.carsService.CreateCar(input.Car),
                UserId           = userId,
                OpensSaleCounter = 0,
            };

            foreach (var image in input.Images)
            {
                var extension = Path.GetExtension(image.FileName).TrimStart('.');

                if (!this.allowedExtensions.Any(x => extension.EndsWith(x)))
                {
                    throw new Exception($"Invalid image extension {extension}");
                }

                var resizedImage = this.imageSharpsService.GetResizedImage(image);

                var imageUrls = await this.cloudinaryService.Upload(this.cloudinary, image);

                var dbImage = new Image
                {
                    AddedByUserId   = userId,
                    Extension       = extension,
                    ImageUrl        = imageUrls.Key,
                    ResizedImageUrl = imageUrls.Value,
                };

                saleToAdd.Images.Add(dbImage);
            }

            await this.salesRepository.AddAsync(saleToAdd);

            await this.salesRepository.SaveChangesAsync();

            await this.carExtrasService.AddExtrasToDbAsync(saleToAdd.CarId, input.CarExtras);

            return(saleToAdd.Id);
        }
コード例 #10
0
        public async Task <IActionResult> Add()
        {
            IList <Item> items      = context.Items.Include(s => s.Supplier).ToList();
            IList <Item> usersItems = new List <Item>();

            foreach (Item item in items)
            {
                var authorizationResult = await _authorizationService.AuthorizeAsync(User, item, new ManageItemAccessRequirement());

                if (authorizationResult.Succeeded)
                {
                    usersItems.Add(item);
                }
            }
            AddSaleViewModel addSaleViewModel = new AddSaleViewModel(usersItems);

            return(View(addSaleViewModel));
        }
コード例 #11
0
        public AddSaleViewModel GetAddSaleViewModel()
        {
            AddSaleViewModel saleViewModel = new AddSaleViewModel()
            {
                Cars = this.DbContext.Cars.Select(car => new AddSaleCarViewModel()
                {
                    Id    = car.Id,
                    Make  = car.Make,
                    Model = car.Model
                }),
                Customers = this.DbContext.Customers.Select(customer => new AddSaleCustomerViewModel()
                {
                    Id   = customer.Id,
                    Name = customer.Name
                })
            };

            return(saleViewModel);
        }
コード例 #12
0
        public ActionResult Create()
        {
            var cars      = this.context.Cars.ToList();
            var customers = this.context.Customers.ToList();
            var addSaleVm = new AddSaleViewModel();

            addSaleVm.Car = cars.Select(x => new SelectListItem()
            {
                Text  = $"{x.Make} {x.Model}",
                Value = x.Id.ToString()
            });

            addSaleVm.Customer = customers.Select(x => new SelectListItem()
            {
                Text  = $"{x.Name}",
                Value = x.Id.ToString()
            });
            return(View(addSaleVm));
        }
コード例 #13
0
        public ActionResult Confirm([Bind(Exclude = "Car,Customer")] AddSaleViewModel asvm)
        {
            var car           = this.context.Cars.Find(asvm.CarId);
            var customer      = this.context.Customers.Find(asvm.CustomerId);
            var price         = car.Parts.Sum(p => p.Price);
            var discount      = customer.IsYoungDriver ? asvm.Discount + 5 : asvm.Discount;
            var confirmSaleVm = new ConfirmSaleViewModel()
            {
                Car        = $"{car.Make} {car.Model}",
                Customer   = customer.Name,
                Discount   = discount,
                Price      = price.Value,
                FinalPrice = decimal.Parse((price.Value - ((discount / 100D) * price.Value)).ToString()),
                CarId      = car.Id,
                CustomerId = customer.Id
            };

            return(this.View(confirmSaleVm));
        }
コード例 #14
0
        public IActionResult Add(AddSaleViewModel addSaleViewModel)
        {
            if (ModelState.IsValid)
            {
                Item newSaleItem =
                    context.Items.Single(i => i.ID == addSaleViewModel.ItemID);
                Sale newSale = new Sale
                {
                    Date      = addSaleViewModel.Date,
                    UnitsSold = addSaleViewModel.UnitsSold,
                    Item      = newSaleItem
                };

                context.Sales.Add(newSale);
                context.SaveChanges();

                return(Redirect("/Sale"));
            }

            return(View(addSaleViewModel));
        }
コード例 #15
0
ファイル: SalesService.cs プロジェクト: Ivolekov/SoftUni_3.0
        public AddSaleViewModel GetSalesViewModel()
        {
            AddSaleViewModel       vm        = new AddSaleViewModel();
            IEnumerable <Car>      cars      = this.Context.Cars;
            IEnumerable <Customer> customers = this.Context.Customers;

            IEnumerable <AddSaleCarViewModel>      carVM      = Mapper.Map <IEnumerable <Car>, IEnumerable <AddSaleCarViewModel> >(cars);
            IEnumerable <AddSaleCustomerViewModel> customerVM = Mapper.Map <IEnumerable <Customer>, IEnumerable <AddSaleCustomerViewModel> >(customers);

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

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

            vm.Cars      = carVM;
            vm.Customers = customerVM;
            vm.Discounts = discount;

            return(vm);
        }
コード例 #16
0
        public async Task <IActionResult> Create(AddSaleViewModel input, string captcha)
        {
            if (!await this.captchaValidator.IsCaptchaPassedAsync(captcha))
            {
                this.ModelState.AddModelError(GlobalConstants.ReCaptchaName, GlobalConstants.ReCaptchaErrorMessage);
            }

            if (!this.ModelState.IsValid)
            {
                input.CitiesItems = await this.citiesService.GetAllAsKeyValuePairsAsync(input.CountryId);

                input.Car = await this.carsService.GetCarInputModelWithFilledListItems();

                return(this.View(input));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            int id = 0;

            try
            {
                id = await this.salesService.CreateSaleAsync(input, user.Id);
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError(string.Empty, ex.Message);
                input.CitiesItems = await this.citiesService.GetAllAsKeyValuePairsAsync(input.CountryId);

                input.Car = await this.carsService.GetCarInputModelWithFilledListItems();

                return(this.View(input));
            }

            this.TempData["Message"] = GlobalConstants.SuccessfullyAddedSaleMessage;

            return(this.RedirectToAction(nameof(this.SaleInfo), new { id }));
        }
コード例 #17
0
 public IActionResult Add(AddSaleViewModel saleModel)
 {
     this._services.AddNewSale(saleModel.Car, saleModel.Customer, saleModel.Discount);
     return(this.SelectSale(0));
 }
コード例 #18
0
        public ActionResult Add()
        {
            AddSaleViewModel saleViewModel = this.service.GetAddSaleViewModel();

            return(View(saleViewModel));
        }