public HttpResponse Add(AddCarListingViewModel model) { var checkForErrors = CarService.AddCar(model, this.User.Id); if (checkForErrors.Count != 0) { return(Error(checkForErrors)); } return(Redirect("./All")); }
public List <string> AddCar(AddCarListingViewModel model, string userId) { ICollection <string> modelErrors = Validator.ValidateModel(model); if (modelErrors.Count != 0) { return(modelErrors.ToList()); } var car = new Car { Model = model.Model, Year = model.Year, PictureUrl = model.Image, PlateNumber = model.PlateNumber, OwnerId = userId }; this.Data.Cars.Add(car); this.Data.SaveChanges(); return(modelErrors.ToList()); }