示例#1
0
        public void InsertTa(Ta ta, ref List<string> errors)
        {
            if (ta == null)
            {
                errors.Add("Ta cannot be null");
                throw new ArgumentException();
            }

            if (string.IsNullOrEmpty(ta.FirstName))
            {
                errors.Add("Ta first name cannot be null");
                throw new ArgumentException();
            }

            if (string.IsNullOrEmpty(ta.LastName))
            {
                errors.Add("Ta last name cannot be null");
                throw new ArgumentException();
            }

            if (this.repository.IsNotDuplicateTa(ta, ref errors))
            {
                this.repository.AddTa(ta, ref errors);
            }
            else
            {
                errors.Add("Duplicate Ta");
            }
        }
示例#2
0
        public string InsertTa(Ta ta)
        {
            var errors = new List<string>();
            var repository = new TaRepository(this.entities);
            var service = new TaService(repository);
            service.InsertTa(ta, ref errors);
            if (errors.Count == 0)
            {
                return "ok";
            }

            return "error";
        }
示例#3
0
        public void GetTa()
        {
            var errors = new List<string>();
            var mockRepository = new Mock<ITaRepository>();
            var teachingAssistantService = new TaService(mockRepository.Object);
            var ta_1 = new Ta { FirstName = "hi", LastName = "bye", TaId = 5 };
            var returnTa = new Ta();

            mockRepository.Setup(x => x.FindTaById(5, ref errors)).Returns(ta_1);
            returnTa = teachingAssistantService.GetTaById(5, ref errors);

            Assert.AreEqual(returnTa.TaId, 5);
            Assert.AreEqual(returnTa.FirstName, "hi");
            Assert.AreEqual(returnTa.LastName, "bye");
        }
示例#4
0
        public void GetTaList()
        {
            var errors = new List<string>();
            var mockRepository = new Mock<ITaRepository>();
            var teachingAssistantService = new TaService(mockRepository.Object);
            var ta_List = new List<Ta>();
            var ta_1 = new Ta { FirstName = "hi", LastName = "bye" };
            var ta_2 = new Ta { FirstName = "hi", LastName = "bye" };
            var returnTaList = new List<Ta>();

            ta_List.Add(ta_1);
            ta_List.Add(ta_2);

            mockRepository.Setup(x => x.GetTaList(ref errors)).Returns(ta_List);
            returnTaList = teachingAssistantService.GetTaList(ref errors);

            Assert.AreEqual(returnTaList.Count, 2);
        }
示例#5
0
        public Ta FindTaByName(string ta_name, ref List<string> errors)
        {
            POCO.Ta pocoTa = new POCO.Ta();
            TeachingAssistant db_Ta;
            try
            {
                db_Ta = this.context.TeachingAssistants.Where(x => x.first == ta_name).First();
                if (db_Ta != null)
                {
                    pocoTa.TaId = db_Ta.ta_id;
                    pocoTa.TaType = db_Ta.ta_type_id.ToString();
                    pocoTa.FirstName = db_Ta.first;
                    pocoTa.LastName = db_Ta.last;
                }
            }
            catch (Exception e)
            {
                errors.Add("Error occured in TaRepository.FindTaByName: " + e);
            }

            return pocoTa;
        }
示例#6
0
        public void InsertTa()
        {
            //// Arranage
            var errors = new List<string>();
            var mockRepository = new Mock<ITaRepository>();
            var ta_Service = new TaService(mockRepository.Object);
            var ta_1 = new Ta { TaId = 2, TaType = "bb", FirstName = "cc", LastName = "dd" };

            mockRepository.Setup(x => x.AddTa(ta_1, ref errors));
            mockRepository.Setup(x => x.IsNotDuplicateTa(ta_1, ref errors)).Returns(true);

            //// Act
            ta_Service.InsertTa(ta_1, ref errors);

            //// Assert
            mockRepository.Verify(x => x.AddTa(ta_1, ref errors), Times.Once());
        }
示例#7
0
        public void UpdateTaErrorTest3()
        {
            //// Arranage
            var errors = new List<string>();
            var mockRepository = new Mock<ITaRepository>();
            var teachingAssistantService = new TaService(mockRepository.Object);
            var ta = new Ta { FirstName = "nick", LastName = string.Empty };

            //// Act
            teachingAssistantService.UpdateTa(ta, ref errors);

            //// Assert last name cannot be empty
            Assert.AreEqual(1, errors.Count);
        }
示例#8
0
        public List<Ta> GetTaList(ref List<string> errors)
        {
            List<POCO.Ta> pocoTaList = new List<POCO.Ta>();
            List<TeachingAssistant> db_TaList;
            try
            {
                db_TaList = this.context.TeachingAssistants.Include("TeachingAssistantType").ToList();

                foreach (TeachingAssistant i_ta in db_TaList)
                {
                    var tempPoco = new POCO.Ta();
                    tempPoco.TaId = i_ta.ta_id;
                    tempPoco.TaType = i_ta.TeachingAssistantType.ta_type_desc;
                    tempPoco.FirstName = i_ta.first;
                    tempPoco.LastName = i_ta.last;
                    pocoTaList.Add(tempPoco);
                }
            }
            catch (Exception e)
            {
                errors.Add("Error occured in TaRepository.GetTaList: " + e);
            }

            return pocoTaList;
        }
示例#9
0
        public bool IsNotDuplicateTa(Ta ta, ref List<string> errors)
        {
            var db_Ta = new TeachingAssistant();

            try
            {
                var ta_Type = int.Parse(ta.TaType);
                var isDuplicate = this.context.TeachingAssistants.Where(
                    x => x.first == ta.FirstName &&
                    x.last == ta.LastName &&
                    x.ta_type_id == ta_Type).Count() > 0;

                if (isDuplicate)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            catch (Exception e)
            {
                errors.Add("Error occured in TaRepository.IsDuplicateTa: " + e);
            }

            return false;
        }
示例#10
0
        public void UpdateTa(Ta ta, ref List<string> errors)
        {
            if (ta == null)
            {
                errors.Add("Ta cannot be null");
                throw new ArgumentException();
            }

            if (ta.TaId <= 0)
            {
                errors.Add("Invalid ta_id");
                throw new ArgumentException();
            }

            if (string.IsNullOrEmpty(ta.FirstName))
            {
                errors.Add("Ta first name cannot be null");
                throw new ArgumentException();
            }

            if (string.IsNullOrEmpty(ta.LastName))
            {
                errors.Add("Ta last name cannot be null");
                throw new ArgumentException();
            }

            if (ta.TaId <= 0)
            {
                errors.Add("Taid be null");
                throw new ArgumentException();
            }

            this.repository.UpdateTa(ta, ref errors);
        }
示例#11
0
        public List<Ta> GetTaBySchedule(int scheduleId, ref List<string> errors)
        {
            IEnumerable<course_schedule> db_List;
            IEnumerable<TeachingAssistant> ta_List;
            List<Ta> pocoList = new List<Ta>();

            try
            {
                db_List = this.context.course_schedule.Include("TeachingAssistants").Where(x => x.schedule_id == scheduleId);

                foreach (course_schedule c in db_List)
                {
                    ta_List = c.TeachingAssistants;
                    foreach (TeachingAssistant t in ta_List)
                    {
                        var poco = new Ta();
                        poco.TaId = t.ta_id;
                        poco.FirstName = t.first;
                        poco.LastName = t.last;
                        poco.TaType = t.ta_type_id.ToString();

                        pocoList.Add(poco);
                    }
                }
            }
            catch (Exception e)
            {
                errors.Add("Error occured in ScheduleRepository.GetDays: " + e);
            }

            return pocoList;
        }