public void InsertInstructor(Instructor instructor, ref List<string> errors)
        {
            if (instructor == null)
            {
                errors.Add("Instructor cannot be null");
                throw new ArgumentException();
            }

            if (string.IsNullOrEmpty(instructor.InstructorId))
            {
                errors.Add("Invalid Instructor id");
                throw new ArgumentException();
            }

            if(string.IsNullOrEmpty(instructor.FirstName))
            {
                errors.Add("Instructor requires a first name.");
                throw new ArgumentException();
            }

            if (string.IsNullOrEmpty(instructor.LastName))
            {
                errors.Add("Instructor requires a last name.");
                throw new ArgumentException();
            }

            this.repository.InsertInstructor(instructor, ref errors);
        }
        public string InsertInstructor(Instructor instructor)
        {
            var errors = new List<string>();
            var repository = new InstructorRepository();
            var service = new InstructorService(repository);
            service.InsertInstructor(instructor, ref errors);
            if (errors.Count == 0)
            {
                return "ok";
            }

            return "error";
        }
        public void InsertInstructorTest3()
        {
            //// Arranage
            var errors = new List<string>();
            var mockRepository = new Mock<IInstructorRepository>();
            var instructorService = new InstructorService(mockRepository.Object);
            var instructor = new Instructor { FirstName = string.Empty };

            //// Act
            instructorService.InsertInstructor(instructor, ref errors);

            //// Assert
            Assert.AreEqual(1, errors.Count);
        }
        public Instructor GetInstructorInfo(string id, ref List<string> errors)
        {
            var conn = new SqlConnection(ConnectionString);
            Instructor instructor = null;
            try
            {
                var adapter = new SqlDataAdapter(GetInstructorInfoProcedure, conn)
                {
                    SelectCommand =
                    {
                        CommandType = CommandType.StoredProcedure
                    }
                };
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@instructor_id", SqlDbType.VarChar, 20));

                adapter.SelectCommand.Parameters["@instructor_id"].Value = id;

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

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

                instructor = new Instructor
                {
                    InstructorId = dataSet.Tables[0].Rows[0]["instructor_id"].ToString(),
                    FirstName = dataSet.Tables[0].Rows[0]["first_name"].ToString(),
                    LastName = dataSet.Tables[0].Rows[0]["last_name"].ToString(),
                    Title = dataSet.Tables[0].Rows[0]["title"].ToString()
                };
            }
            catch (Exception e)
            {
                errors.Add("Error: " + e);
            }
            finally
            {
                conn.Dispose();
            }

            return instructor;
        }
        public void InsertInstructor(Instructor instructor, ref List<string> errors)
        {
            var conn = new SqlConnection(ConnectionString);
            try
            {
                var adapter = new SqlDataAdapter(InsertInstructorProcedure, conn)
                {
                    SelectCommand =
                    {
                        CommandType = CommandType.StoredProcedure
                    }
                };
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@instructor_id", SqlDbType.VarChar, 20));
                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("@title", SqlDbType.VarChar, 50));

                adapter.SelectCommand.Parameters["@instructor_id"].Value = instructor.InstructorId;
                adapter.SelectCommand.Parameters["@first_name"].Value = instructor.FirstName;
                adapter.SelectCommand.Parameters["@last_name"].Value = instructor.LastName;
                adapter.SelectCommand.Parameters["@title"].Value = instructor.Title;

                var dataSet = new DataSet();
                adapter.Fill(dataSet);
            }
            catch (Exception e)
            {
                errors.Add("Error: " + e);
            }
            finally
            {
                conn.Dispose();
            }
        }
Пример #6
0
        public void InsertInstructor(Instructor instructor, ref List<string> errors)
        {
            if (instructor == null)
            {
                errors.Add("Instructor cannot be null");
                throw new ArgumentException();
            }

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

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

            if (string.IsNullOrEmpty(instructor.Password))
            {
                errors.Add("Password cannot be null");
                throw new ArgumentException();
            }

            if (this.repository.IsNotDuplicateInstructor(instructor, ref errors))
            {
                this.repository.AddInstructor(instructor, ref errors);
            }
            else
            {
                errors.Add("Instructor already exists");
            }
        }
Пример #7
0
        public void UpdateInstructor(Instructor instructor, ref List<string> errors)
        {
            if (instructor == null)
            {
                errors.Add("Instructor cannot be null");
                throw new ArgumentException();
            }

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

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

            if (instructor.InstructorId <= 0)
            {
                errors.Add("Instructor id be null");
                throw new ArgumentException();
            }

            this.repository.UpdateInstructor(instructor, ref errors);
        }
Пример #8
0
        public void GetInstructor()
        {
            //// Arrange
            var errors = new List<string>();

            Mock<IInstructorRepository> mockRepository = new Mock<IInstructorRepository>();
            InstructorService iserv = new InstructorService(mockRepository.Object);

            Instructor crl = new Instructor()
            {
                InstructorId = 99,
                FirstName = "T",
                LastName = "Test",
                Title = "Tester"
            };

            mockRepository.Setup(x => x.FindInstructorById(99, ref errors)).Returns(crl);

            //// Act
            Instructor temp = iserv.GetInstructor("99", ref errors);

            //// Assert
            Assert.AreEqual(0, errors.Count);
            Assert.AreEqual(99, temp.InstructorId);
            Assert.AreEqual("T", temp.FirstName);
            Assert.AreEqual("Test", temp.LastName);
        }
Пример #9
0
        public List<Instructor> GetInstructorList(ref List<string> errors)
        {
            List<POCO.Instructor> pocoInstructorList = new List<POCO.Instructor>();
            List<instructor> db_instructorList;
            try
            {
                db_instructorList = this.context.instructors.ToList();

                foreach (instructor i_instructor in db_instructorList)
                {
                    var tempPoco = new POCO.Instructor();
                    tempPoco.InstructorId = i_instructor.instructor_id;
                    tempPoco.FirstName = i_instructor.first_name;
                    tempPoco.LastName = i_instructor.last_name;
                    tempPoco.Title = i_instructor.title;

                    pocoInstructorList.Add(tempPoco);
                }
            }
            catch (Exception e)
            {
                errors.Add("Error occured in InstructorRepository.GetInstructorList: " + e);
            }

            return pocoInstructorList;
        }
Пример #10
0
        public Instructor FindInstructorByName(string instName, ref List<string> errors)
        {
            POCO.Instructor pocoInstructor = new POCO.Instructor();
            instructor db_instructor;
            try
            {
                db_instructor = this.context.instructors.Where(x => x.first_name == instName).First();
                if (db_instructor != null)
                {
                    pocoInstructor.InstructorId = db_instructor.instructor_id;
                    pocoInstructor.FirstName = db_instructor.first_name;
                    pocoInstructor.LastName = db_instructor.last_name;
                    pocoInstructor.Title = db_instructor.title;
                }
            }
            catch (Exception e)
            {
                errors.Add("Error occured in InstructorRepository.FindInstructorByName: " + e);
            }

            return pocoInstructor;
        }
Пример #11
0
        public void UpdateInstructorTest()
        {
            //// Arranage
            var errors = new List<string>();

            Mock<IInstructorRepository> mockRepository = new Mock<IInstructorRepository>();
            InstructorService iserv = new InstructorService(mockRepository.Object);

            Instructor ins = new Instructor { InstructorId = 99, FirstName = "Test", LastName = "test" };

            mockRepository.Setup(x => x.UpdateInstructor(ins, ref errors));

            //// Act
            iserv.UpdateInstructor(ins, ref errors);

            //// Assert
            mockRepository.Verify(x => x.UpdateInstructor(ins, ref errors), Times.Once());
        }
Пример #12
0
        public void UpdateInstructorErrorTest3()
        {
            //// Arranage
            var errors = new List<string>();
            var mockRepository = new Mock<IInstructorRepository>();
            var instructorService = new InstructorService(mockRepository.Object);
            var instructor = new Instructor { FirstName = "nick", LastName = string.Empty };

            //// Act
            instructorService.UpdateInstructor(instructor, ref errors);

            //// Assert last name cannot be empty
            Assert.AreEqual(1, errors.Count);
        }
Пример #13
0
        public void UpdateInstructor()
        {
            //// Arranage
            var errors = new List<string>();
            var mockRepository = new Mock<IInstructorRepository>();
            var instructorService = new InstructorService(mockRepository.Object);
            var instructor = new Instructor { InstructorId = 2, FirstName = "bb", LastName = "zz", Title = "NOPE" };

            mockRepository.Setup(x => x.UpdateInstructor(instructor, ref errors));

            //// Act
            instructorService.UpdateInstructor(instructor, ref errors);

            //// Assert
            mockRepository.Verify(x => x.UpdateInstructor(instructor, ref errors), Times.Once());
        }
Пример #14
0
        public void InsertInstructor()
        {
            //// Arranage
            var errors = new List<string>();
            var mockRepository = new Mock<IInstructorRepository>();
            var instructorService = new InstructorService(mockRepository.Object);
            var instructor = new Instructor { InstructorId = 2, FirstName = "bb", LastName = "cc", Title = "nope" };

            mockRepository.Setup(x => x.AddInstructor(instructor, ref errors));
            mockRepository.Setup(x => x.IsNotDuplicateInstructor(instructor, ref errors)).Returns(true);

            //// Act
            instructorService.InsertInstructor(instructor, ref errors);

            //// Assert
            mockRepository.Verify(x => x.AddInstructor(instructor, ref errors), Times.Once());
        }
Пример #15
0
        public string UpdateInstructor(Instructor instructor)
        {
            var errors = new List<string>();
            var repository = new InstructorRepository(this.entities);
            var service = new InstructorService(repository);
            service.UpdateInstructor(instructor, ref errors);

            if (errors.Count == 0)
            {
                return "ok";
            }

            return "error";
        }
Пример #16
0
        public Instructor FindInstructorById(int instId, ref List<string> errors)
        {
            POCO.Instructor pocoInstructor = new POCO.Instructor();
            instructor db_instructor;
            var db_staff = new staff();

            try
            {
                db_instructor = this.context.instructors.Find(instId);
                if (db_instructor != null)
                {
                    db_staff = this.context.staffs.Find(instId);

                    if (db_instructor != null)
                    {
                        pocoInstructor.InstructorId = db_instructor.instructor_id;
                        pocoInstructor.FirstName = db_instructor.first_name;
                        pocoInstructor.LastName = db_instructor.last_name;
                        pocoInstructor.Title = db_instructor.title;
                        pocoInstructor.Password = db_staff.password;
                    }
                }
            }
            catch (Exception e)
            {
                errors.Add("Error occured in InstructorRepository.FindInstructorById: " + e);
            }

            return pocoInstructor;
        }
Пример #17
0
        public List<Instructor> GetInstructorList(ref List<string> errors)
        {
            var conn = new SqlConnection(ConnectionString);
            var instructorList = new List<Instructor>();

            try
            {
                var adapter = new SqlDataAdapter(GetInstructorListProcedure, 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 instructor = new Instructor
                    {
                        InstructorId = dataSet.Tables[0].Rows[i]["instructor_id"].ToString(),
                        FirstName = dataSet.Tables[0].Rows[i]["first_name"].ToString(),
                        LastName = dataSet.Tables[0].Rows[i]["last_name"].ToString(),
                        Title = dataSet.Tables[0].Rows[i]["title"].ToString()
                    };
                    instructorList.Add(instructor);
                }
            }
            catch (Exception e)
            {
                errors.Add("Error: " + e);
            }
            finally
            {
                conn.Dispose();
            }

            return instructorList;
        }