Exemple #1
0
        public async Task <IActionResult> PutEmployee([FromBody] PersonAPI person)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!(await EmployeeExists(person.Ssn)))
            {
                return(BadRequest());
            }

            try
            {
                Employee employee = EmployeeFactory.Get(person, EmployeeEnum.AssistentLibrarian);
                await _repository.UpdateAsync(employee);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!(await EmployeeExists(person.Ssn)))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #2
0
        public void Factory_Create_Employee(string expected, EmployeeEnum empType)
        {
            //Arrange
            PersonAPI person = new PersonAPI()
            {
                Address = "Toldstrupsgade 20", Email = "*****@*****.**", Name = "Michael Schumacher", Password = "******", Phone = "4569637412", PictureId = "testpictureid1", Ssn = 999555111
            };

            //Act
            Employee emp = EmployeeFactory.Get(person, empType);

            //Assert
            Assert.Equal(expected, emp.Title);
        }
Exemple #3
0
        public void Valid_Email(bool expected, string email)
        {
            //Arrange
            PersonAPI person = new PersonAPI()
            {
                Address = "Toldstrupsgade 20", Email = email, Name = "Michael Schumacher", Password = "******", Phone = "4569637412", PictureId = "testpictureid1", Ssn = 123456789
            };

            //Act
            Employee emp = EmployeeFactory.Get(person, EmployeeEnum.DepartmentLibrarian);

            //Assert
            Assert.Equal(expected, (emp == null));
        }
Exemple #4
0
        public async Task <IActionResult> PostEmployee([FromBody] PersonAPI person, [FromRoute] int empType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (await EmployeeExists(person.Ssn))
            {
                return(BadRequest());
            }

            Employee employee = EmployeeFactory.Get(person, (EmployeeEnum)empType);

            if (employee == null)
            {
                return(BadRequest());
            }

            await _repository.AddAsync(employee);

            return(CreatedAtAction("GetEmployee", new { id = employee.Ssn }, employee));
        }
Exemple #5
0
        private LibraryContext GetContextWithData()
        {
            var options = new DbContextOptionsBuilder <LibraryContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var context = new LibraryContext(options);

            context.Employees.Add(EmployeeFactory.Get(new PersonAPI()
            {
                Address   = "Toldstrupsgade 20",
                Email     = "*****@*****.**",
                Name      = "Michael Schumacher",
                Password  = "******",
                Phone     = "1234567896",
                PictureId = "testpictureid1",
                Ssn       = 999555111
            }, EmployeeEnum.AssistentLibrarian));
            context.Employees.Add(EmployeeFactory.Get(new PersonAPI()
            {
                Address   = "Sofiendelsvej 16",
                Email     = "*****@*****.**",
                Name      = "Maria Maria",
                Password  = "******",
                Phone     = "7536974526",
                PictureId = "testpictureid1",
                Ssn       = 523641785
            }, EmployeeEnum.ChiefLibrarian));
            context.Employees.Add(EmployeeFactory.Get(new PersonAPI()
            {
                Address   = "Vesterbro 12",
                Email     = "*****@*****.**",
                Name      = "Jhon Mc'gee",
                Password  = "******",
                Phone     = "7586752727",
                PictureId = "testpictureid1",
                Ssn       = 853147865
            }, EmployeeEnum.CheckOutStaff));
            context.Employees.Add(EmployeeFactory.Get(new PersonAPI()
            {
                Address   = "Jomfru Anne Gade 69",
                Email     = "*****@*****.**",
                Name      = "Daniel Cash",
                Password  = "******",
                Phone     = "5428285452",
                PictureId = "testpictureid1",
                Ssn       = 325845125
            }, EmployeeEnum.DepartmentLibrarian));
            context.Employees.Add(EmployeeFactory.Get(new PersonAPI()
            {
                Address   = "Hobrovej 3",
                Email     = "*****@*****.**",
                Name      = "Will Smith",
                Password  = "******",
                Phone     = "1122334432",
                PictureId = "testpictureid1",
                Ssn       = 112596325
            }, EmployeeEnum.ReferenceLibrarian));

            context.SaveChanges();

            return(context);
        }