public async Task <IActionResult> Edit(int id, [Bind("Id,Titulo,EditorialId,Fecha,Costo,PreciosSugerido,Autor")] Data.Models.Library library) { IActionResult response; if (ModelState.IsValid) { bool result = await _library.UpdateLibrary(library); if (result) { response = RedirectToAction(nameof(Index)); } else { ModelState.AddModelError(string.Empty, "No se pudo editar el Libro"); response = View(library); } } else { response = View(library); } ViewData["EditorialId"] = new SelectList(_editorial.SelectAllEditorial(), "Id", "Nombre", library.EditorialId); return(response); }
public async Task <IActionResult> Create([Bind("Id,Titulo,EditorialId,Fecha,Costo,PreciosSugerido,Autor")] Data.Models.Library library) { IActionResult response; if (ModelState.IsValid) { bool result = await _library.InsertLibrary(library); if (result) { response = RedirectToAction(nameof(Index)); } else { ModelState.AddModelError(string.Empty, "No se pudo crear el Libro"); response = View(library); } } else { response = View(library); } return(response); }
// Handles create library command // Takes in the request and a cancellation token // Throws exceptions for bad request // Returns a library dto public async Task <LibraryDto> Handle(CreateLibraryCommand request, CancellationToken cancellationToken) { if (request.Library == null) { throw new BadRequestException($"A valid {nameof(Data.Models.Library)} must be provided"); } if (!request.Library.IsValid()) { throw new BadRequestException(request.Library.GetValidationErrors()); } var dto = request.Library; var model = new Data.Models.Library() { Name = dto.Name, Address = dto.Address }; Database.Libraries.Add(model); await Database.SaveChangesAsync(); await Mediator.Publish(new LibraryCreatedDomainEvent(model)); return(Mapper.Map <LibraryDto>(model)); }
public Task <bool> UpdateLibrary(Data.Models.Library data) { return(_repository.UpdateLibrary(data)); }
public Task <bool> InsertLibrary(Data.Models.Library data) { return(_repository.InsertLibrary(data)); }