public HttpResponseMessage updatecourseDetail(Courses course) { try { return Request.CreateResponse(HttpStatusCode.OK, _repo.Updatecourse(course)); } catch (Exception) { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
public HttpResponseMessage addloginDetail(Courses course) { try { return Request.CreateResponse(HttpStatusCode.OK, _repo.Addcourse(course)); } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
/// <summary> /// add new course using this method /// </summary> /// <param name="courseObj"></param> /// <returns></returns> public Courses Addcourse(Courses courseObj) { try { courseObj.CreatedDate = DateTime.Now; courseObj.ModifiedDate = DateTime.Now; Courses newcourse = _context.Courses.Add(courseObj); SaveContext(); return newcourse; } catch (Exception) { throw; } }
/// <summary> /// update course using thie method /// </summary> /// <param name="courseObj"></param> /// <returns></returns> public bool Updatecourse(Courses courseObj) { try { Courses course = _context.Courses.Where(x => x.CourseId == courseObj.CourseId).FirstOrDefault(); if (course != null) { course.CourseFee = courseObj.CourseFee; course.CourseName = courseObj.CourseName; course.Duration = courseObj.Duration; course.NumberOfsemester = courseObj.NumberOfsemester; course.ModifiedDate = DateTime.Now; _context.Entry(course).State = System.Data.Entity.EntityState.Modified; SaveContext(); return true; } return false; } catch (Exception) { throw; } }