Example #1
0
        public List <TaTutor> GetTutorByCourseSchedule(int course_schedule_id, ref List <string> errors)
        {
            var talist     = new List <TaTutor>();
            var connection = new SqlConnection(ConnectionString);

            try
            {
                var adapter = new SqlDataAdapter(GetTaScheduleByCourseProcedure, connection)
                {
                    SelectCommand =
                    {
                        CommandType = CommandType.StoredProcedure
                    }
                };

                adapter.SelectCommand.Parameters.Add(new SqlParameter("@course_schedule_id", SqlDbType.Int));

                adapter.SelectCommand.Parameters["@course_schedule_id"].Value = course_schedule_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 ta = new TaTutor
                    {
                        TaTutorId = dataSet.Tables[0].Rows[i]["ta_tutor_id"].ToString(),
                        FirstName = dataSet.Tables[0].Rows[i]["first_name"].ToString(),
                        LastName  = dataSet.Tables[0].Rows[i]["last_name"].ToString(),
                        TaType    =
                            (TaType)
                            Enum.Parse(
                                typeof(TaType),
                                dataSet.Tables[0].Rows[i]["ta_type"].ToString())
                    };
                    talist.Add(ta);
                }
            }
            catch (Exception e)
            {
                errors.Add("Errors: " + e);
            }
            finally
            {
                connection.Dispose();
            }

            return(talist);
        }
        public void UpdateTaTutor(TaTutor ta_tutor, ref List <string> errors)
        {
            if (ta_tutor == null)
            {
                errors.Add("TA/Tutor cannot be null");
                throw new ArgumentException();
            }

            if (string.IsNullOrEmpty(ta_tutor.TaTutorId))
            {
                errors.Add("Invalid TA/Tutor id");
                throw new ArgumentException();
            }

            if (ta_tutor.TaTutorId.Length < 6 || ta_tutor.TaTutorId.Length > 11)
            {
                errors.Add("Invalid TA/Tutor ID");
                throw new ArgumentException();
            }

            if (!this.CheckId(ta_tutor.TaTutorId))
            {
                errors.Add("Invalid TA/Tutor ID");
                throw new ArgumentException();
            }

            if (!this.CheckName(ta_tutor.FirstName))
            {
                errors.Add("Invalid first name");
                throw new ArgumentException();
            }

            if (!this.CheckName(ta_tutor.LastName))
            {
                errors.Add("Invalid last name");
                throw new ArgumentException();
            }

            if ((int)ta_tutor.TaType < 0 || (int)ta_tutor.TaType > 2)
            {
                errors.Add("Invalid ta/tutor type");
                throw new ArgumentException();
            }
            else if (!this.CheckType((int)ta_tutor.TaType))
            {
                errors.Add("Invalid ta/tutor type");
                throw new ArgumentException();
            }

            this.repository.UpdateTaTutor(ta_tutor, ref errors);
        }
        public void InsertTaTutorBadFirstName()
        {
            //// Arranage
            var errors         = new List <string>();
            var mockRepository = new Mock <ITaTutorRepository>();
            var tatutorService = new TaTutorService(mockRepository.Object);
            var tatutor        = new TaTutor {
                TaTutorId = "A0123456", FirstName = "J4ne", LastName = "Doe"
            };

            //// Act
            tatutorService.InsertTaTutor(tatutor, ref errors);

            //// Assert
            Assert.AreEqual(1, errors.Count);
        }
        public void InsertTaTutorErrorTest2()
        {
            //// Arranage
            var errors         = new List <string>();
            var mockRepository = new Mock <ITaTutorRepository>();
            var tatutorService = new TaTutorService(mockRepository.Object);
            var tatutor        = new TaTutor {
                TaTutorId = string.Empty
            };

            //// Act
            tatutorService.InsertTaTutor(tatutor, ref errors);

            //// Assert
            Assert.AreEqual(1, errors.Count);
        }
Example #5
0
        public void UpdateTaTutor(TaTutor ta_tutor, ref List <string> errors)
        {
            var connection = new SqlConnection(ConnectionString);

            try
            {
                var adapter = new SqlDataAdapter(InsertTaInfoProcedure, connection)
                {
                    SelectCommand =
                    {
                        CommandType = CommandType.StoredProcedure
                    }
                };

                adapter.SelectCommand.Parameters.Add(new SqlParameter("@tutor_id", SqlDbType.VarChar, 10));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@first_name", SqlDbType.VarChar, 50));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@last_name", SqlDbType.VarChar, 50));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@ta_type_id", SqlDbType.Int));

                adapter.SelectCommand.Parameters["@tutor_id"].Value   = ta_tutor.TaTutorId;
                adapter.SelectCommand.Parameters["@first_name"].Value = ta_tutor.FirstName;
                adapter.SelectCommand.Parameters["@last_name"].Value  = ta_tutor.LastName;
                adapter.SelectCommand.Parameters["@ta_type_id"].Value = (int)ta_tutor.TaType;

                var dataset = new DataSet();
                adapter.Fill(dataset);
            }
            catch (Exception e)
            {
                errors.Add("Errors : " + e);
            }
            finally
            {
                connection.Dispose();
            }
        }
 public string UpdateTaTutor(TaTutor ta_tutor)
 {
     this.service.UpdateTaTutor(ta_tutor, ref this.errors);
     return(this.errors.Count == 0 ? "ok" : "Error occurred");
 }
Example #7
0
        public TaTutor GetTaTutorInfo(string ta_tutor_id, ref List <string> errors)
        {
            TaTutor tatutor    = null;
            var     connection = new SqlConnection(ConnectionString);

            try
            {
                var adapter = new SqlDataAdapter(GetTaScheduleByCourseProcedure, connection)
                {
                    SelectCommand =
                    {
                        CommandType = CommandType.StoredProcedure
                    }
                };

                var dataSet = new DataSet();
                adapter.Fill(dataSet);

                if (dataSet.Tables[0].Rows.Count == 0)
                {
                    return(null);
                }

                tatutor = new TaTutor
                {
                    TaTutorId = dataSet.Tables[0].Rows[0]["id"].ToString(),
                    FirstName = dataSet.Tables[0].Rows[0]["first"].ToString(),
                    LastName  = dataSet.Tables[0].Rows[0]["last"].ToString(),
                    TaType    = (TaType)
                                Enum.Parse(
                        typeof(TaType),
                        dataSet.Tables[0].Rows[0]["ta_type_id"].ToString())
                };

                if (dataSet.Tables[1].Rows.Count > 0)
                {
                    tatutor.TaTutorSchedule = new List <Schedule>();
                    for (int i = 0; i < dataSet.Tables[1].Rows.Count; i++)
                    {
                        var schedule = new Schedule
                        {
                            ScheduleId = Convert.ToInt32(dataSet.Tables[1].Rows[i]["schedule_id"].ToString()),
                            Year       = dataSet.Tables[1].Rows[i]["year"].ToString(),
                            Quarter    = dataSet.Tables[1].Rows[i]["quarter"].ToString(),
                            Session    = dataSet.Tables[1].Rows[i]["session"].ToString(),
                            Course     = new Course
                            {
                                CourseId    = dataSet.Tables[1].Rows[i]["course_id"].ToString(),
                                Title       = dataSet.Tables[1].Rows[i]["course_title"].ToString(),
                                Description = dataSet.Tables[1].Rows[i]["course_description"].ToString(),
                                CourseLevel =
                                    (CourseLevel)
                                    Enum.Parse(
                                        typeof(CourseLevel),
                                        dataSet.Tables[1].Rows[i]["course_level"].ToString())
                            },
                        };
                        tatutor.TaTutorSchedule.Add(schedule);
                    }
                }
            }
            catch (Exception e)
            {
                errors.Add("Errors: " + e);
            }
            finally
            {
                connection.Dispose();
            }

            return(tatutor);
        }