public CapeReview FindCapeReviewByScheduleId(int schedule_id, ref List<string> errors) { CapeReview pocoCR = new CapeReview(); course_schedule db_schedule = new course_schedule(); cape_reviews db_cr = new cape_reviews(); try { db_schedule = this.context.course_schedule.Find(schedule_id); db_cr = this.context.cape_reviews.Where(x => x.course_id == db_schedule.course_id && x.instructor_id == (int)db_schedule.instructor_id).First(); pocoCR.CapeId = db_cr.cape_id; pocoCR.CourseId = (int)db_cr.course_id; pocoCR.CourseRating = (int)db_cr.course_rating; pocoCR.InstructorId = (int)db_cr.instructor_id; pocoCR.InstructorRating = (int)db_cr.instructor_rating; pocoCR.Summary = db_cr.summary; } catch (Exception e) { errors.Add("Error occured in CapeReviewRepository.FindCapeReviewById: " + e); } return pocoCR; }
public List<CapeReview> FindCapeReviewsByCourseId(int course_id, ref List<string> errors) { List<CapeReview> pocoCrList = new List<CapeReview>(); try { IEnumerable<cape_reviews> db_crList = this.context.cape_reviews.Where(x => x.course_id == course_id); foreach (cape_reviews db in db_crList) { var pocoCr = new CapeReview(); pocoCr.CapeId = db.cape_id; pocoCr.CourseId = (int)db.course_id; pocoCr.InstructorId = (int)db.instructor_id; pocoCr.InstructorRating = (int)db.instructor_rating; pocoCr.Summary = db.summary; pocoCr.CourseRating = (int)db.course_rating; pocoCrList.Add(pocoCr); } } catch (Exception e) { errors.Add("Error occured in CapeReviewRepository.FindCapeReviewById: " + e); } return pocoCrList; }
public string InsertCapeReview(CapeReview cr) { var errors = new List<string>(); var repository = new CapeReviewRepository(this.entities); var service = new CapeReviewService(repository); service.InsertCapeReview(cr, ref errors); if (errors.Count == 0) { return "ok"; } return "Failed cape review insert"; }
public void UpdateCapeReview(CapeReview cr, ref List<string> errors) { cape_reviews db = new cape_reviews(); try { db.cape_id = cr.CapeId; db.instructor_id = cr.InstructorId; db.course_id = cr.CourseId; db.course_rating = cr.CourseRating; db.instructor_rating = cr.InstructorRating; db.summary = cr.Summary; this.context.cape_reviews.Add(db); this.context.SaveChanges(); } catch (Exception e) { errors.Add("Error occured in CapeReviewRepository.UpdateCapeReview: " + e); } }
public void InsertCape(CapeReview cr, ref List<string> errors) { cape_reviews db_CapeReview = new cape_reviews(); try { db_CapeReview.cape_id = cr.CapeId; ////db.instructor_id = this.context.instructors.Where(x => x.last_name == cr.InstructorName).Select(y => y.instructor_id).First(); db_CapeReview.instructor_id = cr.InstructorId; db_CapeReview.course_id = cr.CourseId; db_CapeReview.instructor_rating = cr.InstructorRating; db_CapeReview.summary = cr.Summary; db_CapeReview.course_rating = cr.CourseRating; this.context.cape_reviews.Add(db_CapeReview); this.context.SaveChanges(); } catch (Exception e) { errors.Add("Error occured in CapeReviewRepository.InsertCape: " + e); } }
public void UpdateCapeReviewTest() { //// Arranage var errors = new List<string>(); var mockRepository = new Mock<ICapeReviewRepository>(); var capeReviewService = new CapeReviewService(mockRepository.Object); var capeReview = new CapeReview { CapeId = 1, CourseId = 2, CourseRating = 3, InstructorId = 4, InstructorRating = 5, Summary = "hello" }; mockRepository.Setup(x => x.UpdateCapeReview(capeReview, ref errors)); //// Act capeReviewService.UpdateCapeReview(capeReview, ref errors); //// Assert mockRepository.Verify(x => x.UpdateCapeReview(capeReview, ref errors), Times.Once()); }
public void UpdateCapeReviewErrorTest4() { //// Arranage var errors = new List<string>(); var mockRepository = new Mock<ICapeReviewRepository>(); var capeReviewService = new CapeReviewService(mockRepository.Object); var capeReview = new CapeReview { CapeId = 1, CourseId = 2, CourseRating = 3, InstructorId = 4, InstructorRating = 5, Summary = null }; //// Act capeReviewService.UpdateCapeReview(capeReview, ref errors); //// Assert Assert.AreEqual(1, errors.Count); }
public void InsertCapeReviewErrorTest3() { //// Arranage var errors = new List<string>(); var mockRepository = new Mock<ICapeReviewRepository>(); var capeReviewService = new CapeReviewService(mockRepository.Object); int? nullInt = null; // (int)nullInt var capeReview = new CapeReview { CapeId = 1, CourseId = (int)nullInt, CourseRating = 3, InstructorId = 4, InstructorRating = 5, Summary = "nope" }; //// Act capeReviewService.InsertCapeReview(capeReview, ref errors); //// Assert last name cannot be empty Assert.AreEqual(1, errors.Count); }
public List<CapeCourseReview> GetCapeReviewByCourse(int course_id, ref List<string> errors) { var list = new List<CapeCourseReview>(); var conn = new SqlConnection(ConnectionString); try { var adapter = new SqlDataAdapter(GetCapeReviewByCourseProcedure, conn) { SelectCommand = { CommandType = CommandType.StoredProcedure } }; adapter.SelectCommand.Parameters.Add(new SqlParameter("@course_id", SqlDbType.Int)); adapter.SelectCommand.Parameters["@course_id"].Value = course_id; var dataSet = new DataSet(); adapter.Fill(dataSet); if (dataSet.Tables[0].Rows.Count == 0) { return null; } for (var i = 0; i < dataSet.Tables[0].Rows.Count; i++) { var cape = new CapeReview { CourseScheduleId = Convert.ToInt32(dataSet.Tables[0].Rows[i]["course_schedule_id"].ToString()), Quarter = dataSet.Tables[0].Rows[i]["quarter"].ToString(), Year = dataSet.Tables[0].Rows[i]["year"].ToString(), Course = new Course { CourseId = dataSet.Tables[0].Rows[i]["course_id"].ToString(), Title = dataSet.Tables[0].Rows[i]["course_title"].ToString(), Description = dataSet.Tables[0].Rows[i]["course_description"].ToString() }, Instructor = new Instructor { FirstName = dataSet.Tables[0].Rows[i]["instructor_first_name"].ToString(), LastName = dataSet.Tables[0].Rows[i]["instructor_last_name"].ToString() } }; var capeCourseReview = new CapeCourseReview { CapeDetail = cape, As = Convert.ToInt32(dataSet.Tables[0].Rows[i]["As"].ToString()), Bs = Convert.ToInt32(dataSet.Tables[0].Rows[i]["Bs"].ToString()), Cs = Convert.ToInt32(dataSet.Tables[0].Rows[i]["Cs"].ToString()), Ds = Convert.ToInt32(dataSet.Tables[0].Rows[i]["Ds"].ToString()), Fs = Convert.ToInt32(dataSet.Tables[0].Rows[i]["Fs"].ToString()), TotalReviews = Convert.ToInt32(dataSet.Tables[0].Rows[i]["total"].ToString()), AverageReview = Convert.ToSingle(dataSet.Tables[0].Rows[i]["avg"].ToString()) }; list.Add(capeCourseReview); } } catch (Exception e) { errors.Add("Error: " + e); } finally { conn.Dispose(); } return list; }
public List<CapeReview> GetCapeReviews(string studentId, ref List<string> errors) { var conn = new SqlConnection(ConnectionString); var capeReviewList = new List<CapeReview>(); try { var adapter = new SqlDataAdapter(GetStudentCapeReviews, conn) { SelectCommand = { CommandType = CommandType.StoredProcedure } }; adapter.SelectCommand.Parameters.Add(new SqlParameter("@student_id", SqlDbType.VarChar, 20)); adapter.SelectCommand.Parameters["@student_id"].Value = studentId; var dataSet = new DataSet(); adapter.Fill(dataSet); if (dataSet.Tables[0].Rows.Count == 0) { return null; } for (var i = 0; i < dataSet.Tables[0].Rows.Count; i++) { var capeReview = new CapeReview { CourseScheduleId = Convert.ToInt32(dataSet.Tables[0].Rows[i]["course_schedule_id"].ToString()), Quarter = dataSet.Tables[0].Rows[i]["quarter"].ToString(), Year = dataSet.Tables[0].Rows[i]["year"].ToString(), Course = new Course { Title = dataSet.Tables[0].Rows[i]["course_title"].ToString(), Description = dataSet.Tables[0].Rows[i]["course_description"].ToString() }, Instructor = new Instructor { FirstName = dataSet.Tables[0].Rows[i]["instructor_first_name"].ToString(), LastName = dataSet.Tables[0].Rows[i]["instructor_last_name"].ToString() } }; capeReviewList.Add(capeReview); } } catch (Exception e) { errors.Add("Error: " + e); } finally { conn.Dispose(); } return capeReviewList; }
public void InsertCapeReview(CapeReview cr, ref List<string> errors) { if (cr == null) { errors.Add("Cape Review cannot be null"); throw new ArgumentException(); } if (cr.InstructorId <= 0) { errors.Add("Instructor cannot be null"); throw new ArgumentException(); } if (cr.CourseId <= 0) { errors.Add("Course cannot be null"); throw new ArgumentException(); } if (string.IsNullOrEmpty(cr.Summary)) { errors.Add("Summary cannot be null"); throw new ArgumentException(); } this.repository.InsertCape(cr, ref errors); }