Beispiel #1
0
        public async Task <SellCarViewModel> GetSellCarViewModel(int carId)
        {
            var viewModel = new SellCarViewModel();

            viewModel.Car = await TurnCarToViewModelAsync(_dbContext.Cars.Include(c => c.Photos).First(c => c.Id == carId));

            return(viewModel);
        }
Beispiel #2
0
        public void SellCar(SellCarViewModel viewModel)
        {
            var carInDb = _dbContext.Cars.Find(viewModel.Car.Id);

            carInDb.ActualSellingPrice = Convert.ToInt32(viewModel.SellingPrice);
            carInDb.SellingDate        = DateTime.Today;
            carInDb.SellerId           = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var customer = new Customer
            {
                FirstName    = viewModel.CustomerDetails.FirstName,
                LastName     = viewModel.CustomerDetails.LastName,
                EmailAddress = viewModel.CustomerDetails.EmailAddress,
                PhoneNumber  = viewModel.CustomerDetails.PhoneNumber,
                Car          = carInDb
            };

            _dbContext.Customers.Add(customer);
            _dbContext.SaveChanges();
        }
Beispiel #3
0
        public async Task <ActionResult> sellCar(SellCarViewModel vm)
        {
            if (vm.Comment == null)
            {
                vm.Comment = "";
            }
            if (vm.firstRegistration == null)
            {
                vm.firstRegistration = DateTime.Now.Date;
            }
            if (vm.CarDamage == null)
            {
                vm.CarDamage = "";
            }
            IdentityMessage message = new IdentityMessage();

            message.Subject = "Ik verkoop volgende auto: " + vm.CarBrand + " " + vm.CarModel;
            message.Body    = "<h3>Nieuw bericht van " + vm.SurName + " " + vm.Name + "</h3><br/> <b>Emailadres correspondent:</b> " + vm.Emailaddress + "<br/> <b>Telefoonnummer correspondent:</b> " + vm.Phone + "<br/><b>  Onderwerp: </b> Ik verkoop volgende auto: " + vm.CarBrand + " " + vm.CarModel + "<br/><b> Gegevens auto: </b></br><b>Merk: </b>" + vm.CarBrand + "<br/><b>Model: </b>" + vm.CarModel + "<br/><b>Kilometerstand: </b>" + vm.CarKilometers + "<br/><b>Schade: </b>" + vm.CarDamage + "<br/><b>Kleur: </b>" + vm.Color + "<br/><b>Bouwjaar: </b>" + vm.YearOfConstruction + "<br/><b>Beschrijving: </b>" + vm.CarDescription + "<br/><b>Brandstof: </b>" + vm.fuelChoice.ToString() + "<br/><b>Transmissie: </b>" + vm.transmissionChoice.ToString() + "<br/><b>Eerste inschrijving: </b>" + vm.firstRegistration.ToLongDateString() + "<br/><b>Opmerking: </b>" + vm.Comment + "<br/><br/>";

            List <HttpPostedFileBase> files = vm.files.ToList();

            for (int i = 0; i < files.Count(); i++)
            {
                if (files.ElementAt(i) != null && files.ElementAt(i).ContentLength > 0)
                {
                    MemoryStream target = new MemoryStream();
                    files.ElementAt(i).InputStream.CopyTo(target);
                    byte[] image = target.ToArray();
                    message.Body += "<img alt='' src='data:image;base64," + Convert.ToBase64String(image) + "'style=' width:100%;max-width:600px;height:auto' />";
                }
                else
                {
                    Debug.WriteLine("file null");
                }
            }
            EmailService service = new EmailService();

            await service.SendAsync(message);

            return(RedirectToAction("Index"));
        }
 public IActionResult Sell(SellCarViewModel viewModel)
 {
     _carService.SellCar(viewModel);
     return(RedirectToAction("Index"));
 }
Beispiel #5
0
        public ActionResult SellCar()
        {
            SellCarViewModel vm = new SellCarViewModel();

            return(View(vm));
        }