Ejemplo n.º 1
0
        public HttpResponseMessage UpdateCourse(ApiModels.Course_Model objCourse, String Id)
        {
            try
            {
                var course = from d in db.MstCourses
                             where d.Id == Convert.ToInt32(Id)
                             select d;

                if (course.Any())
                {
                    var updateCourse = course.FirstOrDefault();
                    updateCourse.CourseCode = objCourse.CourseCode;
                    updateCourse.Course     = objCourse.Course;
                    db.SubmitChanges();

                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Course not found!"));
                }
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message));
            }
        }
Ejemplo n.º 2
0
        public HttpResponseMessage AddCourse(ApiModels.Course_Model objCourse)
        {
            try
            {
                Data.MstCourse newCourse = new Data.MstCourse
                {
                    CourseCode = objCourse.CourseCode,
                    Course     = objCourse.Course
                };
                db.MstCourses.InsertOnSubmit(newCourse);
                db.SubmitChanges();

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message));
            }
        }