public void Create(string make, string model, long travelledDistance, IEnumerable <int> parts) { var existingPartIds = db .Parts .Where(p => parts.Contains(p.Id)) .Select(p => p.Id) .ToList(); var car = new Car { Make = make, Model = model, TravelledDistance = travelledDistance }; foreach (var partId in existingPartIds) { car.Parts.Add(new PartCars { PartId = partId }); } db.Add(car); db.SaveChanges(); }
public async Task <IActionResult> Create([Bind("CarModelId,Manufacturer,Model,AddInformations")] CarModel carModel) { if (ModelState.IsValid) { _context.Add(carModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(carModel)); }
public void Create(string name, DateTime birthday, bool isYoungDriver) { var customer = new Customer { Name = name, BirthDay = birthday, IsYoungDriver = isYoungDriver }; db.Add(customer); db.SaveChanges(); }
public async Task <IActionResult> Create([Bind("CarId,ProductionYear,Mileage,AccidentFree,Price,CarModelId, Discount")] Car car) { if (ModelState.IsValid) { _context.Add(car); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CarModelId"] = new SelectList(_context.CarModels, "CarModelId", "Manufacturer", car.CarModelId); return(View(car)); }
public void Create(string name, decimal price, int quantity, int supplierId) { var part = new Part { Name = name, Price = price, Quantity = quantity > 0 ? quantity : 1, SupplierId = supplierId }; db.Add(part); db.SaveChanges(); }