public async Task <IActionResult> Create([Bind("Id,CityName")] City city) { // this code checks if there is a city with the given name in _context int createCounter = 0; foreach (var checkCity in _context.Cities) { if (checkCity.CityName == city.CityName) { createCounter += 1; } } if (createCounter == 0) { if (ModelState.IsValid) { _context.Add(city); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(city)); } else { return(RedirectToAction(nameof(Index))); } }
public async Task <IActionResult> PutCar(long id, Car car) { if (id != car.Id) { return(BadRequest()); } _context.Entry(car).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CarExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <CarType> > PostCarType(CarType carType) { _context.CarTypes.Add(carType); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetCarType), new { id = carType.CarTypeId }, carType)); }
public async Task <string> PutBrand(int id, Brand brand) { if (id != brand.Id) { return("0"); } _context.Entry(brand).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BrandExists(id)) { return("0"); } else { throw; } } _context.SaveChanges(); return("{\"id\":" + id + ",\"stt\":\"" + brand.Status + "\"}"); }
public async Task <ActionResult <Car> > PostCar(Car newCar) { _context.Car.Add(newCar); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetCar), new { id = newCar.Id }, newCar)); }
public async Task <IActionResult> PutProduct(int id, Product product) { if (id != product.ID) { return(BadRequest()); } _context.Entry(product).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutCar([FromRoute] int id, [FromBody] Car car) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != car.ID) { return(BadRequest()); } _context.Entry(car).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CarExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutCarItem(long id, CarItem carItem) { if (id != carItem.Id) { return(BadRequest("The car with this ID does not exist!")); } if (carItem.Year < 2000) { return(BadRequest("Year must be greater than 2000")); } else if (carItem.Price < 100) { return(BadRequest(" The price must be greater than 100")); } _context.Entry(carItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CarItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("Id,ManufacturerName")] Manufacturer manufacturer) { // this code checks if there is a manufacturer with the given name in _context int createMakerCounter = 0; foreach (var checkMaker in _context.Manufacturers) { if (checkMaker.ManufacturerName == manufacturer.ManufacturerName) { createMakerCounter += 1; } } if (createMakerCounter == 0) { if (ModelState.IsValid) { _context.Add(manufacturer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(manufacturer)); } else { return(RedirectToAction(nameof(Index))); } }
public async Task <string> PutUser(int id, User user) { if (id != user.ID) { return("0"); } _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return("0"); } else { throw; } } _context.SaveChanges(); return("{\"id\":" + id + ",\"stt\":\"" + user.Status + "\"}"); }
private static async Task FillCarModelsAsync(CarContext context) { var carModeldata = await File.ReadAllTextAsync("TestData/CarModels.json"); var carModels = JsonSerializer.Deserialize <IEnumerable <CarModel> >(carModeldata); var carMakes = JsonSerializer.Deserialize <IEnumerable <CarMake> >(carModeldata).ToArray(); for (var i = 0; i < carModels.Count(); i++) { var make = context.CarMakes.FirstOrDefault(m => m.Make == carMakes.Skip(i).First().Make); if (make == null) { context.CarMakes.Add(carMakes.Skip(i).First()); await context.SaveChangesAsync(); make = await context.CarMakes.FirstOrDefaultAsync(m => m.Make == carMakes.Skip(i).First().Make); } carModels.Skip(i).First().CarMake = make; context.CarModels.Add(carModels.Skip(i).First()); } await context.SaveChangesAsync(); }
public async Task <IActionResult> Create([Bind("Id,Name,Status")] Brand brand, IFormFile?ful) { var idd = _context.brands.Count() + 1; if (ModelState.IsValid) { if (ful != null) { var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img/pro", idd + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]); using (var stream = new FileStream(path, FileMode.Create)) { await ful.CopyToAsync(stream); } brand.Logo = idd + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]; } else { brand.Logo = "no-image.png"; } _context.Add(brand); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View("Index")); }
public async Task <string> PutCategory(int id, Category category) { if (id != category.ID) { return("0"); } _context.Entry(category).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(id)) { return("0"); } else { throw; } } _context.SaveChanges(); return("{\"id\":" + id + ",\"stt\":\"" + category.Status + "\"}"); }
public async Task <Car> CreateCar(Car car) { _context.Cars.Add(car); await _context.SaveChangesAsync(); return(car); }
public async Task <IActionResult> Create([Bind("Marca,Descripcion,Modelo,Precio,Kilometros,Estado,Foto")] CreateCarViewModel car) { if (ModelState.IsValid) { string guidImagen = null; if (car.Foto != null) { string ficherosImagenes = Path.Combine(hosting.WebRootPath, "img"); guidImagen = Guid.NewGuid().ToString() + car.Foto.FileName; string rutaDefinitiva = Path.Combine(ficherosImagenes, guidImagen); using (var fileStream = new FileStream(rutaDefinitiva, FileMode.Create)) { car.Foto.CopyTo(fileStream); } } Car newCar = new Car(); newCar.Descripcion = car.Descripcion; newCar.Modelo = car.Modelo; newCar.Precio = car.Precio; newCar.Estado = car.Estado; newCar.Kilometros = car.Kilometros; newCar.MarcaId = car.Marca; newCar.PathImg = guidImagen; _context.Add(newCar); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View()); }
public async Task <ActionResult <CarSpecification> > PostCarSpecification(CarSpecification carSpecification) { carSpecification.DateCreateAt = DateTime.Now; _context.CarSpecifications.Add(carSpecification); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetCarSpecification), new { id = carSpecification.CarId }, carSpecification)); }
public async Task <IActionResult> PutCarModel(CarModel car) { _context.Entry(car).State = EntityState.Modified; await _context.SaveChangesAsync(); return(NoContent()); }
public async Task <IActionResult> Create([Bind("ID,Make,Model,Year,VIN,Color,DealershipID")] Car car) { if (ModelState.IsValid) { _context.Add(car); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(car)); }
public async Task <IActionResult> Create([Bind("Id,RegNo,Model,Brand")] Car car) { if (ModelState.IsValid) { _context.Add(car); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(car)); }
public async Task <IActionResult> Create([Bind("id,FirstName,LastName,UserName,Email,Company,Position,BirthDate")] Member member) { if (ModelState.IsValid) { _context.Add(member); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(member)); }
public async Task <IActionResult> Create([Bind("ID,Make")] Manufacturer manufacturer) { if (ModelState.IsValid) { _context.Add(manufacturer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(manufacturer)); }
public async Task <IActionResult> Create([Bind("Id,Nombre")] Marca marca) { if (ModelState.IsValid) { _context.Add(marca); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(marca)); }
public async Task <IActionResult> Create([Bind("ID,UserName,Password,Name,Address,Phone,Status,Gmail,Rule")] User user) { if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View("Index")); }
public async Task <IActionResult> Create([Bind("Id,Manufacturer,Model,EngineCapacity,TypeOfTransmition,AdditionalCharacteristics,PriceRatio,NumberOfType,NameOfType,PhotoWay")] Car car) { if (ModelState.IsValid) { _context.Add(car); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(car)); }
public async Task <IActionResult> Create([Bind("carID,make,model,year,kilometers")] Car car) { if (ModelState.IsValid) { _context.Add(car); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(car)); }
public async Task <IActionResult> Create([Bind("FeatureID,FeatureDescription")] VehicleFeature vehicleFeature) { if (ModelState.IsValid) { _context.Add(vehicleFeature); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(vehicleFeature)); }
public async Task <IActionResult> Create([Bind("ID,Name,Status")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View("Index")); }
public async Task <IActionResult> Create([Bind("ID,Name,Email,PhoneNumber")] Dealership dealership) { if (ModelState.IsValid) { _context.Add(dealership); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(dealership)); }
public async Task <IActionResult> Create([Bind("Car_Name,Car_Plate,Car_Image,Car_Status")] Car car) { if (ModelState.IsValid) { _context.Add(car); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(car)); }
public async Task <IActionResult> Create([Bind("ManufacterID,ManufacterName")] VehicleManufacter vehicleManufacter) { if (ModelState.IsValid) { _context.Add(vehicleManufacter); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(vehicleManufacter)); }
public static async void Initialize(IServiceProvider serviceProvider) { var context = new CarContext(); if (context == null) { return; } if (context.Database.Exists()) { if (!context.Brands.Any()) { context.Bodys.Add(new Body { BodyID = 1, Name = "седан" }); context.Bodys.Add(new Body { BodyID = 2, Name = "хэчбэк" }); context.Bodys.Add(new Body { BodyID = 3, Name = "универсал" }); context.Bodys.Add(new Body { BodyID = 4, Name = "SUV" }); context.Bodys.Add(new Body { BodyID = 5, Name = "пикап" }); context.Bodys.Add(new Body { BodyID = 6, Name = "внедорожник" }); context.Bodys.Add(new Body { BodyID = 7, Name = "кроссовер" }); context.Bodys.Add(new Body { BodyID = 8, Name = "родстер" }); context.Bodys.Add(new Body { BodyID = 9, Name = "кабриолет" }); context.Bodys.Add(new Body { BodyID = 10, Name = "купе" }); context.Bodys.Add(new Body { BodyID = 11, Name = "минвэн" }); context.Bodys.Add(new Body { BodyID = 12, Name = "лимузин" }); await context.SaveChangesAsync(); } if (!context.Brands.Any()) { context.Drives.Add(new Drive { DriveID = 1, Name = "передний" }); context.Drives.Add(new Drive { DriveID = 2, Name = "задний" }); context.Drives.Add(new Drive { DriveID = 3, Name = "полный" }); await context.SaveChangesAsync(); } if (!context.Brands.Any()) { context.Rudders.Add(new Rudder { RudderID = 1, Name = "левый" }); context.Rudders.Add(new Rudder { RudderID = 2, Name = "правый" }); await context.SaveChangesAsync(); } if (!context.Brands.Any()) { context.Transmissions.Add(new Transmission { TransmissionID = 1, Name = "АКПП" }); context.Transmissions.Add(new Transmission { TransmissionID = 2, Name = "МКПП" }); context.Transmissions.Add(new Transmission { TransmissionID = 3, Name = "CVT" }); await context.SaveChangesAsync(); } if (!context.Brands.Any()) { //var nissan = context.Brands.Add(new Brand { BrandId = 1, BrandName = "Nissan", Cars = null }); //var mitsu = context.Brands.Add(new Brand { BrandId = 2, BrandName = "Mitsubishi", Cars = null }); context.Brands.Add(new Brand { BrandName = "Alfa-Romeo"}); context.Brands.Add(new Brand { BrandName = "Audi"}); context.Brands.Add(new Brand { BrandName = "Bmw"}); context.Brands.Add(new Brand { BrandName = "Chaevrolet"}); context.Brands.Add(new Brand { BrandName = "Citroen"}); context.Brands.Add(new Brand { BrandName = "Ferrari"}); context.Brands.Add(new Brand { BrandName = "Fiat"}); context.Brands.Add(new Brand { BrandName = "Ford"}); context.Brands.Add(new Brand { BrandName = "Geely"}); context.Brands.Add(new Brand { BrandName = "Greatwall"}); context.Brands.Add(new Brand { BrandName = "Honda"}); context.Brands.Add(new Brand { BrandName = "Hyundai"}); context.Brands.Add(new Brand { BrandName = "Infiniti"}); context.Brands.Add(new Brand { BrandName = "Jaguar"}); context.Brands.Add(new Brand { BrandName = "Jeep"}); context.Brands.Add(new Brand { BrandName = "Kia"}); context.Brands.Add(new Brand { BrandName = "Lancia"}); context.Brands.Add(new Brand { BrandName = "Land - rover"}); context.Brands.Add(new Brand { BrandName = "Lexus"}); context.Brands.Add(new Brand { BrandName = "Lifan"}); context.Brands.Add(new Brand { BrandName = "Mazda"}); context.Brands.Add(new Brand { BrandName = "Mercedes"}); context.Brands.Add(new Brand { BrandName = "Mgcars"}); context.Brands.Add(new Brand { BrandName = "Mini"}); //context.Brands.Add(new Brand { BrandName = "Mitsubishi"}); // context.Brands.Add(new Brand { BrandName = "Nissan"}); context.Brands.Add(new Brand { BrandName = "Opel"}); context.Brands.Add(new Brand { BrandName = "Peugeot"}); context.Brands.Add(new Brand { BrandName = "Porsche"}); context.Brands.Add(new Brand { BrandName = "Renault"}); context.Brands.Add(new Brand { BrandName = "Seat"}); context.Brands.Add(new Brand { BrandName = "Skoda"}); context.Brands.Add(new Brand { BrandName = "Ssangyong"}); context.Brands.Add(new Brand { BrandName = "Subaru"}); context.Brands.Add(new Brand { BrandName = "Toyota"}); context.Brands.Add(new Brand { BrandName = "Volvo"}); context.Brands.Add(new Brand { BrandName = "Volkswagen", LogoName = "vw"}); context.Brands.Add(new Brand { BrandName = "ВАЗ", LogoName = "autovaz" }); await context.SaveChangesAsync(); } if (!context.Cars.Any()) { } } }