public void Edit (Tesla tesla) { var original = this.Find(tesla.Id); original.Picture = tesla.Picture; original.Price = tesla.Price; original.Range = tesla.Range; original.ChargeTime = tesla.ChargeTime; original.BriefDescription = tesla.BriefDescription; original.FullDescription = tesla.FullDescription; original.Title = tesla.Title; _repo.SaveChanges(); }
// POST: api/Tesla public HttpResponseMessage Post(Tesla tesla) { if (ModelState.IsValid) { if (tesla.Id == 0) { _service.Create(tesla); return Request.CreateResponse(HttpStatusCode.Created, tesla); } else { _service.Edit(tesla); return Request.CreateResponse(HttpStatusCode.OK, tesla); } } return Request.CreateErrorResponse(HttpStatusCode.BadRequest, this.ModelState); }
public void Create (Tesla tesla) { _repo.Add<Tesla>(tesla); _repo.SaveChanges(); }