public async Task <ActionResult <Car> > Post(Car car) { if (car == null) { return(BadRequest()); } DataBaseHistory dataBaseHistory = new DataBaseHistory(); dataBaseHistory.ChangeDate = DateTime.Now; dataBaseHistory.Information = "Добавлен автомабиль: " + car.CarBrand + " " + car.CarModel + " ," + car.CarPruductionYear + "года" + car.CarColor + " цвета"; db.DataBaseHistories.Add(dataBaseHistory); db.Cars.Add(car); await db.SaveChangesAsync(); return(Ok(car)); }
public async Task <ActionResult <Car> > Delete(int id) { Car car = db.Cars.FirstOrDefault(x => x.Id == id); if (car == null) { return(NotFound()); } DataBaseHistory dataBaseHistory = new DataBaseHistory(); dataBaseHistory.ChangeDate = DateTime.Now; dataBaseHistory.Information = "Удален автомабиль: " + car.CarBrand + " " + car.CarModel + " ," + car.CarPruductionYear + "года" + car.CarColor + " цвета"; db.DataBaseHistories.Add(dataBaseHistory); db.Cars.Remove(car); await db.SaveChangesAsync(); return(Ok(car)); }
public async Task <ActionResult <Car> > Put(Car car) { if (car == null) { return(BadRequest()); } if (!db.Cars.Any(x => x.Id == car.Id)) { return(NotFound()); } DataBaseHistory dataBaseHistory = new DataBaseHistory(); dataBaseHistory.ChangeDate = DateTime.Now; dataBaseHistory.Information = "Информация об автомабиле в ячейке " + car.Id + " изменина на:" + car.CarBrand + " " + car.CarModel + " " + car.CarNum + " " + car.CarPruductionYear + " " + car.CarOwnerFirstName + " " + car.CarOwnerLastName; db.DataBaseHistories.Add(dataBaseHistory); db.Update(car); await db.SaveChangesAsync(); return(Ok(car)); }