public async Task <IActionResult> PutMember([FromBody] PersonAPI person) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { Member member = MemberFactory.Get(person, MemberEnum.Student); await _repository.UpdateAsync(member); } catch (DbUpdateConcurrencyException) { if (!(await MemberExists(person.Ssn))) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void Factory_Create_Member(int expected, MemberEnum memType) { PersonAPI person = new PersonAPI() { Address = "Address 2", Email = "*****@*****.**", Name = "Student 2", Password = "******", Phone = "2222222222", PictureId = "std2", Ssn = 223344556 }; Member mem = MemberFactory.Get(person, memType); Assert.Equal(expected, mem.LoanRuleId); }
public async Task <IActionResult> PostMember([FromBody] PersonAPI person, [FromRoute] int memberType) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (await MemberExists(person.Ssn)) { return(BadRequest()); } Member member = MemberFactory.Get(person, (MemberEnum)memberType); if (member == null) { return(BadRequest()); } await _repository.AddAsync(member); return(CreatedAtAction("GetMember", new { id = member.Ssn }, member)); }
private LibraryContext GetContextWithData() { var options = new DbContextOptionsBuilder <LibraryContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var context = new LibraryContext(options); context.Items.AddRange(ItemFactory.Get(new ItemInfo() { Author = "Test Author", Description = "A very good testing book", Title = "The best book" }, "978-3-16-148410-0"), ItemFactory.Get(new ItemInfo() { Author = "Test Author", Description = "A very good testing book", Title = "The best book" }, "978-3-16-148410-1"), ItemFactory.Get(new ItemInfo() { Author = "Test Author", Description = "A very good testing book", Title = "The best book" }, "978-3-16-148410-2"), ItemFactory.Get(new ItemInfo() { Author = "Test Author", Description = "A very good testing book", Title = "The best book" }), ItemFactory.Get(new ItemInfo() { Author = "Test Author", Description = "A very good testing book", Title = "The best book" }), ItemFactory.Get(new ItemInfo() { Author = "Test Author", Description = "A very good testing book", Title = "The best book" })); context.LoanRules.AddRange(new LoanRule() { Id = 1, LoanTime = 5, BookLimit = 5, GracePeriod = 20 }, new LoanRule() { Id = 2, LoanTime = 5, BookLimit = 5, GracePeriod = 20 }); context.Members.AddRange(MemberFactory.Get(new PersonAPI() { Address = "Address 1", Email = "*****@*****.**", Name = "Student 1", Password = "******", Phone = "1111111111", PictureId = "std1", Ssn = 112233446 }, MemberEnum.Student), MemberFactory.Get(new PersonAPI() { Address = "Address 2", Email = "*****@*****.**", Name = "Student 2", Password = "******", Phone = "2222222222", PictureId = "std2", Ssn = 223344556 }, MemberEnum.Student), MemberFactory.Get(new PersonAPI() { Address = "Address 4", Email = "*****@*****.**", Name = "Teacher 1", Password = "******", Phone = "4444444444", PictureId = "tch1", Ssn = 445566778 }, MemberEnum.Teacher), MemberFactory.Get(new PersonAPI() { Address = "Address 5", Email = "*****@*****.**", Name = "Teacher 2", Password = "******", Phone = "5555555555", PictureId = "tch2", Ssn = 556677889 }, MemberEnum.Teacher)); context.SaveChanges(); var items = context.Items.ToList(); context.Loans.AddRange(new Loan(items[4].Id, 112233446), new Loan(items[1].Id, 112233446), new Loan(items[2].Id, 112233446), new Loan(items[3].Id, 112233446)); context.SaveChanges(); // Member 112233445 has 4 loans return(context); }
private LibraryContext GetContextWithData() { var options = new DbContextOptionsBuilder <LibraryContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var context = new LibraryContext(options); context.LoanRules.AddRange(new LoanRule() { Id = 1, LoanTime = 5, BookLimit = 5, GracePeriod = 20 }, new LoanRule() { Id = 2, LoanTime = 5, BookLimit = 5, GracePeriod = 20 }); context.Members.AddRange(MemberFactory.Get(new PersonAPI() { Address = "Address 1", Email = "*****@*****.**", Name = "Student 1", Password = "******", Phone = "1111111111", PictureId = "std1", Ssn = 112233446 }, MemberEnum.Student), MemberFactory.Get(new PersonAPI() { Address = "Address 2", Email = "*****@*****.**", Name = "Student 2", Password = "******", Phone = "2222222222", PictureId = "std2", Ssn = 223344556 }, MemberEnum.Student), MemberFactory.Get(new PersonAPI() { Address = "Address 3", Email = "*****@*****.**", Name = "Student 3", Password = "******", Phone = "3333333333", PictureId = "std3", Ssn = 334455667 }, MemberEnum.Student), MemberFactory.Get(new PersonAPI() { Address = "Address 4", Email = "*****@*****.**", Name = "Teacher 1", Password = "******", Phone = "4444444444", PictureId = "tch1", Ssn = 445566778 }, MemberEnum.Teacher), MemberFactory.Get(new PersonAPI() { Address = "Address 5", Email = "*****@*****.**", Name = "Teacher 2", Password = "******", Phone = "5555555555", PictureId = "tch2", Ssn = 556677889 }, MemberEnum.Teacher), MemberFactory.Get(new PersonAPI() { Address = "Address 6", Email = "*****@*****.**", Name = "Teacher 3", Password = "******", Phone = "6666666666", PictureId = "tch3", Ssn = 667788990 }, MemberEnum.Teacher)); context.SaveChanges(); return(context); }