コード例 #1
0
        internal string Delete(PeopleHobby cs)
        {
            PeopleHobby exists = _phr.Find(cs);

            if (exists == null)
            {
                throw new Exception("Invalid Id Combination");
            }
            _phr.Delete(exists.Id);
            return("Successfully Deleted");
        }
コード例 #2
0
        internal string Create(PeopleHobby newData)
        {
            PeopleHobby exists = _phr.Find(newData);

            if (exists != null)
            {
                throw new Exception("Student already enrolled");
            }
            _phr.Create(newData);
            return("Successfully Joined");
        }
コード例 #3
0
 public ActionResult <String> Edit([FromBody] PeopleHobby cs)
 {
     try
     {
         return(Ok(_phs.Delete(cs)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
コード例 #4
0
 public ActionResult <String> Create([FromBody] PeopleHobby newData)
 {
     try
     {
         return(Ok(_phs.Create(newData)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
コード例 #5
0
        internal void Create(PeopleHobby newData)
        {
            string sql = @"
            INSERT INTO peoplehobbys 
            (personId, hobbyId) 
            VALUES 
            (@personId, @hobbyId);
            SELECT LAST_INSERT_ID();
            ";
            int    id  = _db.ExecuteScalar <int>(sql, newData);

            newData.Id = id;
            return;
        }
コード例 #6
0
        internal PeopleHobby Find(PeopleHobby ph)
        {
            string sql = "SELECT * FROM peoplehobbys WHERE (personId = @personId AND hobbyId = @hobbyId)";

            return(_db.QueryFirstOrDefault(sql, ph));
        }