private static void AssertBoardOfDirectors(BoardOfDirectors expected, BoardOfDirectors actual)
        {
            Assert.NotNull(expected);
            Assert.NotNull(actual);

            AssertPerson(expected.President, actual.President);
            AssertPerson(expected.VicePresident, actual.VicePresident);
        }
        private static void AssertBoardOfDirectors(BoardOfDirectors expected, JToken actual)
        {
            Assert.NotNull(expected);
            Assert.NotNull(actual);

            var jPresidentToken = actual.SelectToken(expected.GetMemberName(x => x.President));

            AssertPerson(expected.President, jPresidentToken);

            var jVicePresidentToken = actual.SelectToken(expected.GetMemberName(x => x.VicePresident));

            AssertPerson(expected.VicePresident, jVicePresidentToken);
        }
Esempio n. 3
0
        public ActionResult Create(CreateBODMemberViewModel addViewModel, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                var boardOfDirector = new BoardOfDirectors()
                {
                    Title       = addViewModel.Title,
                    FirstName   = addViewModel.FirstName,
                    LastName    = addViewModel.LastName,
                    Email       = addViewModel.Email,
                    Description = addViewModel.Description,
                };

                //byte[] uploadedFile = new byte[file.InputStream.Length];
                //addViewModel.File.InputStream.Read(uploadedFile, 0, file.ContentLength);
                if (file != null)
                {
                    var imageBeforeResize = Image.FromStream(file.InputStream);
                    var imageAfterResize  = ResizeImage(imageBeforeResize, 400, 500);

                    var resizedByteArray = ImageToByte(imageAfterResize);

                    boardOfDirector.PhotoContent = resizedByteArray;
                    boardOfDirector.MimeType     = file.ContentType;

                    db.BoardOfDirectors.Add(boardOfDirector);
                    db.SaveChanges();

                    return(RedirectToAction("Admin"));
                }
                else
                {
                    db.BoardOfDirectors.Add(boardOfDirector);
                    db.SaveChanges();

                    return(RedirectToAction("Admin"));
                }
            }
            else
            {
                return(View());
            }
        }
Esempio n. 4
0
        public ActionResult GetBoDImage(int?id)
        {
            var boardOfDirector = new BoardOfDirectors();

            if (id == null)
            {
                return(new HttpNotFoundResult());
            }

            boardOfDirector = db.BoardOfDirectors.Find(id);

            if (boardOfDirector.MimeType != null && boardOfDirector.PhotoContent != null)
            {
                return(File(boardOfDirector.PhotoContent, boardOfDirector.MimeType));
            }
            else
            {
                return(new FilePathResult(HttpContext.Server.MapPath("~/Content/blankProfileImage.jpeg"), "image/jpeg"));
            }
        }
        public void TestDeepCloneableDeepCopyWithCompositeObject()
        {
            // Arrange
            var president = new Person
            {
                PersonId  = "1234",
                LastName  = "Doe",
                FirstName = "John"
            };
            var vicePresident = new Person
            {
                PersonId  = "5678",
                LastName  = "Doe",
                FirstName = "Jane"
            };
            var boardOfDirectors = new BoardOfDirectors
            {
                President     = president,
                VicePresident = vicePresident
            };

            // Act
            var deepCopy = boardOfDirectors.DeepCopy();

            // Assert
            Assert.NotNull(deepCopy);
            Assert.False(Object.ReferenceEquals(boardOfDirectors, deepCopy));

            Assert.Equal(president.PersonId, deepCopy.President.PersonId);
            Assert.Equal(president.LastName, deepCopy.President.LastName);
            Assert.Equal(president.FirstName, deepCopy.President.FirstName);

            Assert.Equal(vicePresident.PersonId, deepCopy.VicePresident.PersonId);
            Assert.Equal(vicePresident.LastName, deepCopy.VicePresident.LastName);
            Assert.Equal(vicePresident.FirstName, deepCopy.VicePresident.FirstName);
        }
        public void TestDeepCloneableDeepCopyWithComplexObject()
        {
            // Arrange
            var president = new Person
            {
                PersonId  = "1111",
                FirstName = "George",
                LastName  = "Washington"
            };
            var vicePresident = new Person
            {
                PersonId  = "2222",
                FirstName = "John",
                LastName  = "Adams"
            };
            var boardOfDirectors = new BoardOfDirectors
            {
                President     = president,
                VicePresident = vicePresident
            };

            var employee0 = new Employee
            {
                PersonId       = "1234",
                LastName       = "Doe",
                FirstName      = "John",
                EmployeeNumber = "1111111111"
            };
            var employee1 = new Employee
            {
                PersonId       = "5678",
                LastName       = "Doe",
                FirstName      = "Jane",
                EmployeeNumber = "2222222222"
            };
            var employees = new People
            {
                PersonCollection = new List <Person>
                {
                    employee0,
                    employee1
                }
            };

            var company = new Company
            {
                CompanyId        = "Acme",
                CompanyName      = "Acme, Inc.",
                BoardOfDirectors = boardOfDirectors,
                CurrentEmployees = employees
            };

            // Act
            var deepCopy = company.DeepCopy();

            // Assert
            Assert.NotNull(deepCopy);
            Assert.False(Object.ReferenceEquals(company, deepCopy));

            Assert.Equal(company.CompanyId, deepCopy.CompanyId);
            Assert.Equal(company.CompanyName, deepCopy.CompanyName);

            Assert.NotNull(deepCopy.BoardOfDirectors);

            Assert.Equal(president.PersonId, deepCopy.BoardOfDirectors.President.PersonId);
            Assert.Equal(president.LastName, deepCopy.BoardOfDirectors.President.LastName);
            Assert.Equal(president.FirstName, deepCopy.BoardOfDirectors.President.FirstName);

            Assert.Equal(vicePresident.PersonId, deepCopy.BoardOfDirectors.VicePresident.PersonId);
            Assert.Equal(vicePresident.LastName, deepCopy.BoardOfDirectors.VicePresident.LastName);
            Assert.Equal(vicePresident.FirstName, deepCopy.BoardOfDirectors.VicePresident.FirstName);

            Assert.NotNull(deepCopy.CurrentEmployees);
            Assert.NotNull(deepCopy.CurrentEmployees.PersonCollection);
            Assert.Equal(2, deepCopy.CurrentEmployees.PersonCollection.Count);

            Assert.Equal(employee0.PersonId, deepCopy.CurrentEmployees.PersonCollection[0].PersonId);
            Assert.Equal(employee0.LastName, deepCopy.CurrentEmployees.PersonCollection[0].LastName);
            Assert.Equal(employee0.FirstName, deepCopy.CurrentEmployees.PersonCollection[0].FirstName);

            Assert.IsType <Employee>(deepCopy.CurrentEmployees.PersonCollection[0]);
            var deepCopyAsEmployee0 = (Employee)deepCopy.CurrentEmployees.PersonCollection[0];

            Assert.Equal(employee0.EmployeeNumber, deepCopyAsEmployee0.EmployeeNumber);

            Assert.Equal(employee1.PersonId, deepCopy.CurrentEmployees.PersonCollection[1].PersonId);
            Assert.Equal(employee1.LastName, deepCopy.CurrentEmployees.PersonCollection[1].LastName);
            Assert.Equal(employee1.FirstName, deepCopy.CurrentEmployees.PersonCollection[1].FirstName);

            Assert.IsType <Employee>(deepCopy.CurrentEmployees.PersonCollection[1]);
            var deepCopyAsEmployee1 = (Employee)deepCopy.CurrentEmployees.PersonCollection[1];

            Assert.Equal(employee1.EmployeeNumber, deepCopyAsEmployee1.EmployeeNumber);
        }