public void DeleteWaitlist(Waitlist waitlist, ref List<string> errors) { var conn = new SqlConnection(ConnectionString); try { var adapter = new SqlDataAdapter(DeleteWaitlistProcedure, conn) { SelectCommand = { CommandType = CommandType .StoredProcedure } }; adapter.SelectCommand.Parameters.Add(new SqlParameter("@student_id", SqlDbType.VarChar, 25)); adapter.SelectCommand.Parameters.Add(new SqlParameter("@schedule_id", SqlDbType.Int)); adapter.SelectCommand.Parameters["@student_id"].Value = waitlist.StudentId; adapter.SelectCommand.Parameters["@schedule_id"].Value = waitlist.ScheduleId; var dataSet = new DataSet(); adapter.Fill(dataSet); } catch (Exception e) { errors.Add("Error: " + e); } finally { conn.Dispose(); } }
public void InsertWaitlistErrorTest2() { //// Arranage var errors = new List<string>(); var mockRepository = new Mock<IWaitlistRepository>(); var waitlistservice = new WaitlistService(mockRepository.Object); var waitlist = new Waitlist { StudentId = string.Empty }; //// Act waitlistservice.InsertWaitlist(waitlist, ref errors); //// Assert Assert.AreEqual(1, errors.Count); }
public string InsertWaitlist(Waitlist waitlist) { var errors = new List<string>(); var repository = new WaitlistRepository(); var service = new WaitlistService(repository); service.InsertWaitlist(null, ref errors); if (errors.Count == 0) { return "ok"; } return "error"; }
public string UpdateStudent(Waitlist waitlist) { var errors = new List<string>(); var repository = new WaitlistRepository(); var service = new WaitlistService(repository); service.UpdateWaitlist(waitlist, ref errors); if (errors.Count == 0) { return "ok"; } return "error"; }
public void UpdateWaitlist(Waitlist waitlist, ref List<string> errors) { if (waitlist == null) { errors.Add("waitlist cannot be null"); throw new ArgumentException(); } if (string.IsNullOrEmpty(waitlist.StudentId)) { errors.Add("Invalid schdule id"); throw new ArgumentException(); } if (string.IsNullOrEmpty(waitlist.ScheduleId)) { errors.Add("Invalid student id"); throw new ArgumentException(); } this.repository.UpdateWaitlist(waitlist, ref errors); }
public List<Waitlist> GetWaitlist(ref List<string> errors) { var conn = new SqlConnection(ConnectionString); var waitList = new List<Waitlist>(); try { var adapter = new SqlDataAdapter(GetWaitlistProcedure, conn) { SelectCommand = { CommandType = CommandType.StoredProcedure } }; 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 waitlist = new Waitlist { StudentId = dataSet.Tables[0].Rows[i]["student_id"].ToString(), ScheduleId = dataSet.Tables[0].Rows[i]["schdule_id"].ToString(), Waitlist_Id = dataSet.Tables[0].Rows[i]["Waitlist_id"].ToString() }; waitList.Add(waitlist); } } catch (Exception e) { errors.Add("Error: " + e); } finally { conn.Dispose(); } return waitList; }