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

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

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

            if (string.IsNullOrEmpty(admin.Email))
            {
                errors.Add("Admin requires an email.");
                throw new ArgumentException();
            }

            if (string.IsNullOrEmpty(admin.Password))
            {
                errors.Add("Admin requires a password.");
                throw new ArgumentException();
            }

            this.repository.UpdateAdmin(admin, ref errors);
        }
Example #2
0
        public void UpdateAdmin(Admin adminPoco, ref List<string> errors)
        {
            if (adminPoco == null)
            {
                errors.Add("Admin cannot be null");
                throw new ArgumentException();
            }

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

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

            if (adminPoco.Id <= 0)
            {
                errors.Add("Admin Id cannot be null");
                throw new ArgumentException();
            }

            this.repository.UpdateAdmin(adminPoco, ref errors);
        }
        public string InsertAdmin(Admin admin)
        {
            var errors = new List<string>();
            var repository = new AdminRepository();
            var service = new AdminService(repository);
            service.InsertAdmin(admin, ref errors);
            if (errors.Count == 0)
            {
                return "ok";
            }

            return "error";
        }
        public void InsertAdminTest2()
        {
            //// Arrange
            var errors = new List<string>();
            var mockRepository = new Mock<IAdminRepository>();
            var adminService = new AdminService(mockRepository.Object);
            var admin = new Admin { Email = string.Empty, FirstName = string.Empty, LastName = string.Empty, Password = string.Empty };

            //// Act
            adminService.InsertAdmin(admin, ref errors);

            //// Assert
            Assert.AreEqual(4, errors.Count);
        }
Example #5
0
        public string UpdateAdminInfo(Admin admin)
        {
            var errors = new List<string>();
            var repository = new AdminRepository(this.entities);
            var service = new AdminService(repository);
            service.UpdateAdmin(admin, ref errors);

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

            return "error";
        }
        public Admin GetAdmin(int id, ref List<string> errors)
        {
            var conn = new SqlConnection(ConnectionString);
            Admin admin = null;
            try
            {
                var adapter = new SqlDataAdapter(GetAdminProcedure, conn)
                {
                    SelectCommand =
                    {
                        CommandType = CommandType.StoredProcedure
                    }
                };
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@admin_id", SqlDbType.VarChar, 20));

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

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

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

                admin = new Admin
                {
                    Id = Convert.ToInt32(dataSet.Tables[0].Rows[0]["admin_id"].ToString()),
                    FirstName = dataSet.Tables[0].Rows[0]["first_name"].ToString(),
                    LastName = dataSet.Tables[0].Rows[0]["last_name"].ToString(),
                    Email = dataSet.Tables[0].Rows[0]["email"].ToString(),
                    Password = dataSet.Tables[0].Rows[0]["password"].ToString()
                };
            }
            catch (Exception e)
            {
                errors.Add("Error: " + e);
            }
            finally
            {
                conn.Dispose();
            }

            return admin;
        }
Example #7
0
        public void GetAdminErrorTest3()
        {
            //// Arranage
            var errors = new List<string>();
            var mockRepository = new Mock<IAdminRepository>();
            var adminService = new AdminService(mockRepository.Object);
            var adminPoco = new Admin()
            {
                FirstName = "hi",
                LastName = string.Empty
            };

            //// Act
            adminService.GetAdminById(0, ref errors);

            //// Assert instructor object not null
            Assert.AreEqual(1, errors.Count);
        }
Example #8
0
        public void UpdateAdmin()
        {
            //// Arranage
            var errors = new List<string>();
            var mockRepository = new Mock<IAdminRepository>();
            var adminService = new AdminService(mockRepository.Object);
            var adminPoco = new Admin()
            {
                FirstName = "hi",
                LastName = "bye",
                Id = 1
            };

            mockRepository.Setup(x => x.UpdateAdmin(adminPoco, ref errors));
            //// Act
            adminService.UpdateAdmin(adminPoco, ref errors);

            //// Assert instructor object not null
            mockRepository.Verify(x => x.UpdateAdmin(adminPoco, ref errors), Times.Once());
        }
Example #9
0
        public Admin FindAdminById(int admin_id, ref List<string> errors)
        {
            POCO.Admin pocoAdmin = new POCO.Admin();
            admin db_Admin;
            try
            {
                db_Admin = this.context.admins.Find(admin_id);
                if (db_Admin != null)
                {
                    pocoAdmin.Id = db_Admin.admin_id;
                    pocoAdmin.FirstName = db_Admin.First;
                    pocoAdmin.LastName = db_Admin.Last;
                }
            }
            catch (Exception e)
            {
                errors.Add("Error occured in AdminRepository.FindAdminById: " + e);
            }

            return pocoAdmin;
        }
Example #10
0
        public List<Admin> GetAdminList(ref List<string> errors)
        {
            List<POCO.Admin> pocoAdminList = new List<POCO.Admin>();
            IEnumerable<admin> db_AdminList;
            try
            {
                db_AdminList = this.context.admins;

                foreach (admin i_admin in db_AdminList)
                {
                    var tempPoco = new POCO.Admin();
                    tempPoco.Id = i_admin.admin_id;
                    tempPoco.FirstName = i_admin.First;
                    tempPoco.LastName = i_admin.Last;
                    pocoAdminList.Add(tempPoco);
                }
            }
            catch (Exception e)
            {
                errors.Add("Error occured in TaRepository.GetTaList: " + e);
            }

            return pocoAdminList;
        }
        public void InsertAdmin(Admin admin, ref List<string> errors)
        {
            var conn = new SqlConnection(ConnectionString);
            try
            {
                var adapter = new SqlDataAdapter(InsertAdminProcedure, conn)
                {
                    SelectCommand =
                    {
                        CommandType = CommandType.StoredProcedure
                    }
                };
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@admin_id", SqlDbType.VarChar, 20));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@email", SqlDbType.VarChar, 50));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@password", SqlDbType.VarChar, 50));
                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["@admin_id"].Value = admin.Id;
                adapter.SelectCommand.Parameters["@email"].Value = admin.Email;
                adapter.SelectCommand.Parameters["@password"].Value = admin.Password;
                adapter.SelectCommand.Parameters["@first_name"].Value = admin.FirstName;
                adapter.SelectCommand.Parameters["@last_name"].Value = admin.LastName;

                var dataSet = new DataSet();
                adapter.Fill(dataSet);
            }
            catch (Exception e)
            {
                errors.Add("Error: " + e);
            }
            finally
            {
                conn.Dispose();
            }
        }
 public string UpdateAdminInfo(Admin admin)
 {
     //// 136 TODO : update admin info here...
     return "updated not yet implemented";
 }