示例#1
0
 // simple validation
 bool validationIsOk(CustomersInterest interest)
 {
     if (interest.CustomerIdInterested == 0 || interest.CustomerIdInteresting == 0)
     {
         return(false);
     }
     return(true);
 }
示例#2
0
        // 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));
        }
示例#3
0
        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));
        }
示例#4
0
        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));
        }
示例#5
0
        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));
        }