public async Task UpdateLibrary(LibraryDto input) { List <string> errorList = new List <string>(); var data = await GetLibraryById(input.Id); data.Name = input.Name; data.DistrictId = input.DistrictId; data.ProvinceId = input.ProvinceId; LibraryValidator validator = new LibraryValidator(); ValidationResult validationResult = validator.Validate(data); if (!validationResult.IsValid) { foreach (var failure in validationResult.Errors) { errorList.Add(string.Format("{0}", failure.ErrorMessage)); } string errorString = string.Join(" ", errorList.ToArray()); throw new UserFriendlyException(errorString); } await _libraryRepository.UpdateAsync(data); }
public async Task AddLibrary(LibraryDto input) { List <string> errorList = new List <string>(); var library = new Library { Name = input.Name, DistrictId = input.DistrictId, ProvinceId = input.ProvinceId }; LibraryValidator validator = new LibraryValidator(); ValidationResult validationResult = validator.Validate(library); if (!validationResult.IsValid) { foreach (var failure in validationResult.Errors) { errorList.Add(string.Format("{0}", failure.ErrorMessage)); } string errorString = string.Join(" ", errorList.ToArray()); throw new UserFriendlyException(errorString); } await _libraryRepository.InsertAsync(library); }
private async void And_the_library_exists() { var addressDto = new AddressDto() { Type = EAddressTypeDto.Library, Street = "TestStreet", Number = "123", City = "TestCity", ZipCode = "12345", Country = "TestCountry" }; var libraryDto = new LibraryDto() { Name = "TestLibrary", Address = addressDto }; var libDtoJson = JsonConvert.SerializeObject(libraryDto, new StringEnumConverter()); var response = await _client.PostAsync("/v1/libraries", new StringContent(libDtoJson, Encoding.UTF8, "application/json")); var createdDto = JsonConvert.DeserializeObject <LibraryDto>(await response.Content.ReadAsStringAsync()); _libraryDto = createdDto; }
public ChapterContentAssert(HttpResponseMessage response, LibraryDto library) { _response = response; _libraryId = library.Id; _library = library; _chapterContent = response.GetContent <ChapterContentView>().Result; }
public async Task <ActionResult <LibraryDto> > CreateLibrary([FromBody] LibraryDto dto) { // Return CreateAtAction() instead of Ok() to recieve 201 status instead of 200 return(CreatedAtAction(nameof(CreateLibrary), await Mediator.Send(new CreateLibraryCommand() { Library = dto }))); }
public async Task Setup() { _library = LibraryBuilder.Build(); _account = AccountBuilder.InLibrary(_library.Id).AsInvitation().Build(); _response = await Client.PostObject($"/accounts/invitations", new ResendInvitationCodeRequest() { Email = _account.Email }); }
public static DbLibrary ToDbModel(this LibraryDto dto) { return(new DbLibrary() { Id = dto.Id, Name = dto.Name, Address = dto.Address.ToDbModel() }); }
public LibraryAssert ShouldBeSameAs(LibraryDto expectedLibrary) { _view.Name.Should().Be(expectedLibrary.Name); _view.Language.Should().Be(expectedLibrary.Language); _view.SupportsPeriodicals.Should().Be(expectedLibrary.SupportsPeriodicals); _view.PrimaryColor.Should().Be(expectedLibrary.PrimaryColor); _view.SecondaryColor.Should().Be(expectedLibrary.SecondaryColor); return(this); }
public async Task <IActionResult> PostLibrary([FromBody] LibraryDto dto) { var dbLibrary = dto.ToDbModel(); var created = await _libraryRepository.Create(Guid.NewGuid(), dbLibrary.Name, dbLibrary.Address); var createdDto = created.ToDto(); return(Created($"/{createdDto.Id}", createdDto)); }
public async Task <IActionResult> CreateLibrary([FromBody] LibraryDto libraryDto) { var library = mapper.Map <LibraryDto, Library>(libraryDto); library.LastUpdate = DateTime.Now; context.Libraries.Add(library); await context.SaveChangesAsync(); var result = mapper.Map <Library, LibraryDto>(library); return(Ok(result)); }
public async Task Setup() { _library = LibraryBuilder.Build(); _response = await Client.PostObject($"/accounts/invite", new InviteUserRequest { Name = _name, Email = _email, Role = Role.Admin }); }
private static LibraryDto[] GetLibraries() { LibraryDto firstLibrary = new LibraryDto { LibraryName = "Jo Bowl", Sections = new SectionDto() { Name = "Horror", Books = new BookDto[] { new BookDto() { Name = "It", Author = "Stephen King", Description = "Here you can put description about the book" }, new BookDto() { Name = "Frankenstein", Author = "Mary Shelley", Description = "Here you can put description about the book" } } }, CardPrice = 20.30m }; LibraryDto secondLibrary = new LibraryDto { LibraryName = "Kevin Sanchez", Sections = new SectionDto() { Name = "Comedy", Books = new BookDto[] { new BookDto() { Name = "The Diary of a Nobody", Author = "George Grossmith and Weeden Grossmith", Description = "Here you can put description about the book" }, new BookDto() { Name = "Queen Lucia", Author = "E F Benson", Description = "Here you can put description about the book" } } }, CardPrice = 43.35m }; return(new LibraryDto[] { firstLibrary, secondLibrary }); }
public async Task Setup() { _library = LibraryBuilder.Build(); _account = AccountBuilder.InLibrary(_library.Id).AsInvitation().Build(); _response = await Client.PostObject($"/accounts/register/{_account.InvitationCode}", new RegisterRequest { Name = _name, Password = _password, AcceptTerms = true }); }
public IHttpActionResult AddLibrary([FromBody] LibraryDto newLibrary) { try { var dbLibrary = Mapper.Map <LibraryDto, library>(newLibrary); db.libraries.Add(dbLibrary); db.SaveChanges(); return(new ReturnWrapper(Mapper.Map <library, LibraryDto>(dbLibrary), $"Library {dbLibrary.ID} added to database")); } catch (Exception) { return(new ReturnWrapper(HttpStatusCode.BadRequest, "Could not add library to database")); } }
private async Task SetUp() { var memberTask = _mediator.Send(new GetSignedInMember(User, LibraryId)); var membersTask = _mediator.Send(new GetMembersOfLibrary(LibraryId)); var libraryTask = _mediator.Send(new GetLibraryDtoById(LibraryId)); var rolesTask = _mediator.Send(new GetRolesForLibrary(LibraryId)); Member = await memberTask.ConfigureAwait(false); Members = await membersTask.ConfigureAwait(false); Library = await libraryTask.ConfigureAwait(false); Roles = await rolesTask.ConfigureAwait(false); }
public async Task Setup() { var name = RandomData.String; var password = RandomData.String; _library = LibraryBuilder.Build(); _account = AccountBuilder.InLibrary(_library.Id).AsInvitation().Build(); _response = await Client.PostObject($"/accounts/register/{Guid.NewGuid().ToString("N")}", new RegisterRequest { Name = name, Password = password, AcceptTerms = true }); }
public static Library FromDto(LibraryDto dto) { return(new Library { Id = dto.Id, Authors = dto.Authors, Description = dto.Description, IsLatestVersion = dto.IsLatestVersion, Key = dto.Key, OldVersion = dto.OldVersion, Published = dto.Published, ReleaseNotes = dto.ReleaseNotes, Title = dto.Title, Version = dto.Version, }); }
public async Task Setup() { var name = RandomData.String; var password = RandomData.String; _library = LibraryBuilder.Build(); _account = AccountBuilder.InLibrary(_library.Id) .AsInvitation().ExpiringInvitation(DateTime.UtcNow.AddDays(-1)).Build(); _response = await Client.PostObject($"/accounts/register/{_account.InvitationCode}", new RegisterRequest { Name = name, Password = password, AcceptTerms = true }); }
public async Task <ActionResult> Put(int id, [FromBody] LibraryDto book) { var getBook = await _libaryRepository.GetBook(id); if (!ModelState.IsValid) { return(BadRequest("Not a valid model.")); } try { _mapper.Map(book, getBook); await _libaryRepository.SaveChanges(); return(Ok(_mapper.Map <LibraryDto>(getBook))); } catch (Exception) { return(NotFound("There is no a such this model.")); } }
// Private helper method that sets up new library DTO private LibraryDto SetupLibraryDto(string name = "") { var address = new Address() { LocationAddressLine1 = RandomFactory.GetStreetAddress(), LocationAddressLine2 = "", LocationCity = RandomFactory.GetCity(), LocationStateProvince = RandomFactory.GetState(), LocationZipCode = RandomFactory.GetZip(), LocationCountry = "US" }; var dto = new LibraryDto() { Name = name, Address = address }; return(dto); }
public async Task Create_MissingAddress_NullReferenceException() { await ExecuteWithDb((db) => { var handler = new CreateLibraryCommandHandler( MockMediator.Object, db, Mapper, MockAuthorizationService.Object); var dto = new LibraryDto() { Name = RandomFactory.GetLibraryName(), Address = null }; return(handler.Handle(new CreateLibraryCommand() { Library = dto }, default)); }); }
public async Task <ActionResult> Post([FromBody] LibraryDto libary) { if (!ModelState.IsValid) { return(BadRequest("Not a valid model.")); } Library book; try { if (libary == null) { return(BadRequest()); } book = _mapper.Map <Library>(libary); await _libaryRepository.AddBook(book); } catch (Exception) { return(BadRequest("Not a valid model.")); } return(Created(new Uri("/api/Libary", UriKind.Relative), book)); }
public LibraryDtoBuilder() { _libraryDto = WithDefaults(); }
internal static LibraryAssert ShouldMatch(this LibraryView view, LibraryDto dto) { return(LibraryAssert.FromObject(view, dto.Id) .ShouldBeSameAs(dto)); }
public static void AddLibrary(this IDbConnection connection, LibraryDto library) { var id = connection.ExecuteScalar <int>("Insert Into Library (Name, Language, SupportsPeriodicals, PrimaryColor, SecondaryColor) OUTPUT Inserted.Id VALUES (@Name, @Language, @SupportsPeriodicals, @PrimaryColor, @SecondaryColor)", library); library.Id = id; }
public async Task UpdateAsync(LibraryDto lib) => await _db.Libraries.Where(x => x.Id == lib.Id).UpdateAsync(x => new Library { Name = lib.Name, Address = lib.Address });