public int Add(Consultant consultant) { int newId = _consultants.Max(c => c.ID) + 1; consultant.ID = newId; _consultants.Add(consultant); return newId; }
public void Put([FromUri] int id, Consultant consultant) { // check if consultant exists var oldConsultant = _repository.GetAll().FirstOrDefault(c => c.ID == id); if (oldConsultant == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } consultant.ID = id; consultant.Owner = Thread.CurrentPrincipal.Identity.Name; _repository.Update(consultant); }
public HttpResponseMessage Post(Consultant consultant) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } consultant.Owner = Thread.CurrentPrincipal.Identity.Name; var id = _repository.Add(consultant); var response = new HttpResponseMessage(HttpStatusCode.Created); response.Headers.Location = new Uri(Request.RequestUri.AbsoluteUri + "/" + id.ToString()); return response; }
public void Update(Consultant consultant) { var oldConsulant = _consultants.Single(c => c.ID == consultant.ID); _consultants.Remove(oldConsulant); _consultants.Add(consultant); }