// simple validation bool validationIsOk(CustomersInterest interest) { if (interest.CustomerIdInterested == 0 || interest.CustomerIdInteresting == 0) { return(false); } return(true); }
// GET /api/CustomersInterest/1 public IHttpActionResult GetCustomerInterest(long id) { CustomersInterest interest = m_db.CustomersInterest.SingleOrDefault(cus => cus.Id == id); if (interest == null) { return(NotFound()); } return(Ok(interest)); }
public IHttpActionResult DeleteCustomersInterest(long id) { CustomersInterest interest = m_db.CustomersInterest.Find(id); if (interest == null) { return(NotFound()); } m_db.CustomersInterest.Remove(interest); m_db.SaveChanges(); return(Ok(interest)); }
public IHttpActionResult UpdateCustomersInterest(CustomersInterest interest) { if (!validationIsOk(interest)) { return(BadRequest()); } CustomersInterest CusInterest = m_db.CustomersInterest.Find(interest.Id); if (CusInterest == null) { return(NotFound()); } CusInterest.CustomerIdInterested = interest.CustomerIdInterested; CusInterest.CustomerIdInteresting = interest.CustomerIdInteresting; m_db.SaveChanges(); return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult CreateCustomersInterest1(CustomersInterest interest) { if (!validationIsOk(interest)) { return(BadRequest()); } //CustomersInterest CusInterest = m_db.CustomersInterest.Find(interest.Id); //if (CusInterest == null) //{ // return NotFound(); //} //CusInterest.CustomerIdInterested = interest.CustomerIdInterested; //CusInterest.CustomerIdInteresting = interest.CustomerIdInteresting; m_db.CustomersInterest.Add(interest); m_db.SaveChanges(); //m_db.SaveChanges(); return(StatusCode(HttpStatusCode.NoContent)); }