// DELETE api/values/5
 public void Delete(int id)
 {
     using (var context = new MyFirstDBContext())
     {
         var associate = context.Set <Associate>().FirstOrDefault(a => a.Id == id);
         context.Set <Associate>().Remove(associate);
     }
 }
 // POST api/values
 public void Post([FromBody] Associate value)
 {
     using (var context = new MyFirstDBContext())
     {
         context.Set <Associate>().Add(value);
         context.SaveChanges();
     }
 }
Beispiel #3
0
 // POST api/values
 public void Post([FromBody] ContactInfo value)
 {
     using (var context = new MyFirstDBContext())
     {
         context.Set <ContactInfo>().Add(value);
         context.SaveChanges();
     }
 }
        // GET api/values/5
        public AssociateModel Get(int id)
        {
            AssociateModel associateToReturn;

            using (var context = new MyFirstDBContext())
            {
                var associate = context.Set <Associate>().FirstOrDefault(a => a.Id == id);
                associateToReturn = CastAssociate(associate);
            }

            return(associateToReturn);
        }
        // GET api/values
        public IEnumerable <AssociateModel> Get()
        {
            List <AssociateModel> associateList;

            using (var context = new MyFirstDBContext())
            {
                associateList = context.Set <Associate>().ToList()
                                .ConvertAll(CastAssociate);
            }

            return(associateList);
        }
Beispiel #6
0
        // GET api/values/5
        public ContactModel Get(int id)
        {
            ContactModel contactToReturn;

            using (var context = new MyFirstDBContext())
            {
                var contact = context.Set <ContactInfo>().FirstOrDefault(c => c.Id == id);
                contactToReturn = CastContactInfo(contact);
            }

            return(contactToReturn);
        }
Beispiel #7
0
        // GET api/values
        public IEnumerable <ContactWithAssociateModel> Get()
        {
            List <ContactWithAssociateModel> contactList;

            using (var context = new MyFirstDBContext())
            {
                contactList = context.Set <ContactInfo>()
                              .Include(ci => ci.Associate).ToList()
                              .ConvertAll(CastContactInfoWithAssociate);
            }

            return(contactList);
        }