public static LibraryDTO MapToLibraryDto(this IDbCommand command) { using (var reader = command.ExecuteReader()) { var books = new List <BookDTO>(); while (reader.Read()) { try { books.Add(new BookDTO { ID = reader["ID"] != DBNull.Value ? (int)reader["ID"] : 0, ISBN = reader["ISBN"] != DBNull.Value ? (string)reader["ISBN"] : string.Empty, Title = reader["Title"] != DBNull.Value ? (string)reader["Title"] : string.Empty, AuthorName = reader["AuthorName"] != DBNull.Value ? (string)reader["AuthorName"] : string.Empty, Genre = reader["Genre"] != DBNull.Value ? (string)reader["Genre"] : string.Empty, LenderID = reader["LenderID"] != DBNull.Value ? int.Parse(reader["LenderID"].ToString()) : -1, }); } catch (Exception ex) { //TODO lOG details of the record that failed to read and the exception return(null); } } var libraryDTO = new LibraryDTO { Books = books, TotalBooks = books.Count }; return(libraryDTO); } }
public Library MapDtoToLibrary(LibraryDTO libraryDTO, Library library) { library.Address = libraryDTO.Address; library.Name = libraryDTO.Name; library.Telephone = libraryDTO.Telephone; return(library); }
public async Task <IActionResult> UpdateLibrary(long id, LibraryDTO libraryDTO) { if (id != libraryDTO.Id) { return(BadRequest()); } var library = await _context.Libraries.FindAsync(id); if (library == null) { return(NotFound()); } library.Id = libraryDTO.Id; library.Address = libraryDTO.Address; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) when(!LibraryExists(id)) { return(NotFound()); } return(NoContent()); }
public async Task <IActionResult> UpdateLibrary(int id, LibraryDTO libraryDTO) { //Compare if the id in the parameter matches the LibraryId in libraryDTO if (id != libraryDTO.LibraryId) { //Return a Bad Request to the user if it doesn't return(BadRequest()); } //Using the id, find the Library in the database var library = await dbContext.Libraries.FindAsync(id); //Compare if the library was found if (library == null) { //Return a Not Found response if the Library wasn't found return(NotFound()); } //Update the values of the Library library.Address = libraryDTO.Address + " (verified at: " + DateTime.Now + ")"; //Try to save the changes, if there's an error return a Not Found Request try { await dbContext.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) when(!LibraryExists(id)) { return(NotFound()); } //Return a No Content reponse to the user return(NoContent()); }
public LibraryDTO FilterBooks(BookFilter bookFilter) { try { LibraryDTO libraryDto = null; if (bookFilter != null && (!string.IsNullOrWhiteSpace(bookFilter.ISBN) || (!string.IsNullOrWhiteSpace(bookFilter.AuthorName) && !string.IsNullOrWhiteSpace(bookFilter.Title)))) { libraryDto = _bookRepository.FilterBooks(bookFilter); if (libraryDto == null || libraryDto.Books == null || libraryDto.Books.Count() < 1) { libraryDto = GetBooksFromLibraryExpress(_urlHttpClient, _bookRepository, bookFilter); } } else { libraryDto = GetBooksFromLibraryExpress(_urlHttpClient, _bookRepository, bookFilter); } return(libraryDto); } catch (Exception ex) { //TODO: Log this the exception information along with the method details to the database for Error tracing //Allowing the exception be rethrown so that LOG4NET can log there is a problem on the api end point return(null); } }
public void AddLibrary(LibraryDTO libraryDTO) { var library = LibraryCoreConverter.ToDAL(libraryDTO); library.SongsIds = new List <Guid>(); libraryDbList.InsertOne(library); }
public LibraryDTO LibraryInfo(int libId) { GenericRepository <Libraries> generic = new GenericRepository <Libraries>(_context); LibraryDTO library = (LibraryDTO)generic.FindById(libId); return(library); }
private Library MapToLibrary(LibraryDTO library) { return(new Library { Name = library.Name, Address = library.Address, Telephone = library.Telephone }); }
public Guid Add(LibraryDTO libraryDTO) { var library = LibraryCoreConverter.ToDAL(libraryDTO); library.Id = new Guid(); _context.Libraries.Add(library); return(library.Id); }
public Library Post(LibraryDTO value) { Library model = new Library() { Name = value.Name, Location = value.Location }; return(ILibraryRepository.Create(model)); }
public async Task <LibraryDTO> GetLibraryDetail(int LibraryId) { var output = new LibraryDTO(); var result = _repoWrapper.Library.GetLibDetail(LibraryId); if (result != null) { output = _mapper.Map <LibraryDTO>(result); output.Content = HttpUtility.HtmlDecode(output.Content); } return(output); }
public ApiResultDTO Adicionar(LibraryDTO entity) { var Apiresult = new ApiResultDTO(); var categoria = new Category { Nombre = entity.Nombres, Descripcion = entity.Descripcion }; bookStoreContext.Categories.Add(categoria); bookStoreContext.SaveChanges(); Apiresult.Mensaje = Messages.RegistrosExitoso; return(Apiresult); }
public static Library ToDAL(LibraryDTO libraryDTO) { if (libraryDTO == null) { return(null); } return(new Library() { Id = libraryDTO.Id, Name = libraryDTO.Name, }); }
public Library Put(int id, LibraryDTO value) { Library model = ILibraryRepository.Get(id); if (value.Name != null) { model.Name = value.Name; } if (value.Location != null) { model.Location = value.Location; } return(ILibraryRepository.Update(model)); }
public override Task <AddLibraryResponse> AddLibrary(AddLibraryRequest request, ServerCallContext context) { var library = new LibraryDTO() { Id = Guid.Parse(request.Id), Name = request.Name }; _libraryService.AddLibrary(library); var response = new AddLibraryResponse(); return(Task.FromResult(response)); }
public async Task <LibraryDTO> DetailLibrary(int?Library_ID) { LibraryDTO output = new LibraryDTO(); string apiUrl = $"/api/v1/Library/GetLibraryDetail"; string paramRequest = $"?LibraryId={Library_ID}"; var response = await _client.GetAsync(apiUrl + paramRequest); if (response.IsSuccessStatusCode) { string responseStream = await response.Content.ReadAsStringAsync(); output = JsonConvert.DeserializeObject <LibraryDTO>(responseStream); } return(output); }
public async Task <ActionResult <Library> > CreateTodoItem(LibraryDTO libraryDTO) { var library = new Library { Address = libraryDTO.Address }; _context.Libraries.Add(library); await _context.SaveChangesAsync(); return(CreatedAtAction( nameof(GetLibrary), new { id = library.Id }, LibraryDTO(library))); }
public ApiResultDTO Adicionar(LibraryDTO entity) { var Apiresult = new ApiResultDTO(); var Autores = new Author { Nombre = entity.Nombres, Apellidos = entity.Apellidos, FechaNacimiento = (DateTime)entity.FechaNacimiento }; bookStoreContext.Authors.Add(Autores); bookStoreContext.SaveChanges(); Apiresult.Mensaje = Messages.RegistrosExitoso; return(Apiresult); }
public async Task <ActionResult <Library> > CreateLibrary(LibraryDTO libraryDTO) { //Create a new Library Object using the LibraryDTO Library library = new Library(libraryDTO.Address); //Update the Address library.Address += " (verified at: " + DateTime.Now + ")"; //Save the new Library into the database dbContext.Libraries.Add(library); await dbContext.SaveChangesAsync(); //Return a new LibraryDTO object of the newly created library return(CreatedAtAction(nameof(GetLibraryById), new { id = library.LibraryId }, new LibraryDTO(library))); }
public ApiResultDTO Adicionar(LibraryDTO entity) { var Apiresult = new ApiResultDTO(); var Book = new Book { NombreLibro = entity.Nombres, ISBN = entity.ISBN, AutoresIdAutor = (int)entity.IdAutor, CategoriasIdCategoria = (int)entity.IdCategoria }; this.bookStoreContext.Books.Add(Book); this.bookStoreContext.SaveChanges(); Apiresult.Mensaje = Messages.RegistrosExitoso; return(Apiresult); }
public ApiResultDTO Editar(int id, LibraryDTO entity) { var Apiresult = new ApiResultDTO(); var editarcategoria = bookStoreContext.Categories.FirstOrDefault(t => t.IdCategoria == id); if (editarcategoria != null) { editarcategoria.Descripcion = entity.Descripcion; editarcategoria.Nombre = entity.Nombres; Apiresult.Mensaje = Messages.EdicionExitosa; bookStoreContext.SaveChanges(); } else { Apiresult.Mensaje = Messages.NoExisteId; } return(Apiresult); }
public ApiResultDTO Editar(int id, LibraryDTO entity) { var Apiresult = new ApiResultDTO(); var editarAutor = bookStoreContext.Authors.FirstOrDefault(t => t.IdAutor == id); if (editarAutor != null) { editarAutor.Nombre = entity.Nombres; editarAutor.Apellidos = entity.Apellidos; editarAutor.FechaNacimiento = (DateTime)entity.FechaNacimiento; bookStoreContext.SaveChanges(); Apiresult.Mensaje = Messages.EdicionExitosa; } else { Apiresult.Mensaje = Messages.NoExisteId; } return(Apiresult); }
public ApiResultDTO Editar(int id, LibraryDTO entity) { var Apiresult = new ApiResultDTO(); var Book = bookStoreContext.Books.FirstOrDefault(t => t.IdLibro == id); if (Book != null) { Book.NombreLibro = entity.Nombres; Book.ISBN = entity.ISBN; Book.CategoriasIdCategoria = (int)entity.IdCategoria; Book.AutoresIdAutor = (int)entity.IdAutor; Apiresult.Mensaje = Messages.EdicionExitosa; bookStoreContext.SaveChanges(); } else { Apiresult.Mensaje = Messages.NoExisteId; } return(Apiresult); }
protected LibraryDTO GetBooksFromLibraryExpress(IUrlHttpClient urlHttpClient, IBookRepository bookRepository, BookFilter bookFilter) { try { var libraryRequest = GenerateLibraryBookRequest(bookFilter); //Go fetch from external service ExpressLibraryApi var libraryResponse = urlHttpClient.HttpGet(libraryRequest).Result; var libraryDto = ProcessExternalLibraryResponse(libraryResponse); if (libraryDto != null && libraryDto.Books != null && libraryDto.Books.Count > 0) { try { var newLibraryDto = new LibraryDTO(); var ourbooks = bookRepository.AddBooks(libraryDto.Books); newLibraryDto.Books = ourbooks; newLibraryDto.TotalBooks = ourbooks.Count; return(newLibraryDto); } catch (Exception ex) { //TODO: Log this the exception information along with the method details to the database for Error tracing //Allowing the exception be rethrown so that LOG4NET can log there is a problem on the api end point return(null); } } return(libraryDto); } catch (Exception ex) { //TODO: Log this the exception information along with the method details to the database for Error tracing //Allowing the exception be rethrown so that LOG4NET can log there is a problem on the api end point return(null); } }
public async Task <IActionResult> LibraryDetail() { var url = RouteData.Values["url"]; int Library_ID = Utils.RegexRouteIdFromUrl(url.ToString()); if (Library_ID == 0) // Error Redirect 301 { //Response.StatusCode = 301; //Response.Headers("Location", "https://daninhbinhvinhquang.vn/may-de-ban"); //Response.End(); } //Get Menu ViewBag.MenuMachine = await _repoWrapper.ProductCategory.GetLstMenuByParentId(654); ViewBag.MenuMaterials = await _repoWrapper.ProductCategory.GetLstMenuByParentId(652); ViewBag.MenuServices = await _repoWrapper.ProductCategory.GetLstMenuByParentId(651); ViewBag.MenuHeader = await _repoWrapper.Video.GetLstVideoCate(); ViewBag.MetaTags = await _repoWrapper.Setting.GetSetting(); LibraryDTO model = await _repoWrapper.Library.DetailLibrary(Library_ID); if (model.Library_ID != 0) { var libCateInfo = await _repoWrapper.Library.LibraryCategoryById((int)model.LibraryCategory_ID); ViewBag.NameCate = libCateInfo.Name; //lấy ra kiến thức liên quan liên quan ViewBag.SameArticle = await _repoWrapper.Library.LstRelatelLibrary((int)model.LibraryCategory_ID, model.Library_ID); ViewBag.CateId = model.LibraryCategory_ID; return(View(model)); } else { return(Redirect("/Error/404")); } }
public ApiResultDTO Put(int id, [FromBody] LibraryDTO entity) { return(_Library.Editar(id, entity)); }
public ApiResultDTO Post([FromBody] LibraryDTO entity) { return(_Library.Adicionar(entity)); }
protected LibraryCommandBase(long id, LibraryDTO entity) { Id = id; Entity = entity; }
public UpdateLibraryCommand(long id, LibraryDTO update) : base(id, update) { }
protected LibraryCommandBase(LibraryDTO entity) { Entity = entity; }