Example #1
0
        public async Task <IActionResult> OnPost()
        {
            if (ImageOfCar != null)
            {
                var file = Path.Combine("uploads", ImageOfCar.FileName);

                using (var fileStream = new FileStream(Path.Combine(environment.ContentRootPath, "wwwroot\\", file), FileMode.Create))
                {
                    await ImageOfCar.CopyToAsync(fileStream);
                }
                file = "/" + file;

                InputCar.Image = file;
            }

            await InitCar((int)InputCar.Id);

            if (ModelState.IsValid)
            {
                await carManager.UpdateCar(Car.Id, InputCar);

                return(Redirect("/companies/cars/" + InputCar.CompanyId));
            }
            return(Page());
        }
Example #2
0
        public async Task <IActionResult> OnPostAsync(IList <CarInvidual> inviduals)
        {
            var file = Path.Combine("uploads", ImageOfCar.FileName);

            using (var fileStream = new FileStream(Path.Combine(environment.ContentRootPath, "wwwroot\\", file), FileMode.Create))
            {
                await ImageOfCar.CopyToAsync(fileStream);
            }
            file = "/" + file;


            if (ModelState.IsValid)
            {
                Company selectedCompany = await companyManager.GetCompany(InputCar.CompanyId);

                if (selectedCompany == null)
                {
                    ModelState.AddModelError("NoCompany", "Company not found.");

                    await setDropDowns();

                    return(Page());
                }
                foreach (CarInvidual ci in inviduals)
                {
                    await carManager.AddNewCarAsync(new Car
                    {
                        Brand            = InputCar.Brand,
                        Price            = (int)InputCar.Price,
                        Image            = file,
                        IsFuelFull       = (bool)InputCar.IsFuelFull,
                        Seat             = (int)InputCar.Seat,
                        Year             = (int)InputCar.Year,
                        Door             = (int)InputCar.Door,
                        Transmission     = (Transmission)InputCar.Transmission,
                        Climate          = (bool)InputCar.Climate,
                        Category         = (Category)InputCar.Category,
                        Bag              = (int)InputCar.Bag,
                        Company          = selectedCompany,
                        Plate            = ci.Plate,
                        PickUpLocationId = InputCar.LocationId
                    });
                }

                return(RedirectToPage("/"));
            }
            await setDropDowns();

            return(Page());
        }