예제 #1
0
        public IHttpActionResult PostAddPerson(Person newPerson)
        {
            using (PeopleDBEntities context = new PeopleDBEntities())
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest());
                }

                var personObj = context.People.FirstOrDefault(p => p.id == newPerson.id);
                if (personObj != null)
                {
                    personObj.fname     = newPerson.fname;
                    personObj.lname     = newPerson.lname;
                    personObj.age       = newPerson.age;
                    personObj.addr      = newPerson.addr;
                    personObj.interests = newPerson.interests;
                    personObj.picture   = newPerson.picture;
                }
                else
                {
                    context.People.Add(newPerson);
                }

                context.SaveChanges();

                return(Ok());
            }
        }
예제 #2
0
 public IHttpActionResult GetPeople()
 {
     using (PeopleDBEntities context = new PeopleDBEntities())
     {
         var personList = context.People.ToList();
         return(Ok(personList));
     }
 }
예제 #3
0

        
 public BaseRepository(IDbFactory dbFactory)
 {
     _dbFactory = dbFactory;
     _dbContext = _dbFactory.Init();
     _dbSet     = _dbContext.Set <T>();
 }
예제 #5
0
 public HomeController()
 {
     _db = new PeopleDBEntities();
 }