public async Task <ResponseMODEL> DeleteAsync(int id) { try { var resultProcess = await bookDAL.GetAsync(id); if (resultProcess.IsApproved) { if ((Book)resultProcess.ObjectResult != null) { return(await bookDAL.DeleteAsync((Book)resultProcess.ObjectResult)); } else { return(ResponseMODEL.Instance(false, "Transaccion Rechazada", "No es posible eliminar el libro", "No existe un libro que coincida con el codigo enviado")); } } else { return(resultProcess); } } catch (Exception ex) { return(ResponseMODEL.Instance(false, "Error Controlado", "Se controlo un error en la aplicacion.", ex.Message, ex)); } }
public async Task <ResponseMODEL> GetAsync(int id) { try { using (LibraryContext db = new LibraryContext()) { var result = await db.Editorials.FindAsync(id); return(ResponseMODEL.Instance(true, "Transaccion Exitosa", "Consulta exitosa a la tabla \"Editorial\"", null, result)); } } catch (Exception ex) { return(ResponseMODEL.Instance(false, "Error Controlado", "Se controlo un error en la aplicacion. Ver detalle", ex.Message, ex)); } }
public async Task <ResponseMODEL> DeleteAsync(Editorial model) { try { using (LibraryContext db = new LibraryContext()) { db.Editorials.Remove(model); await db.SaveChangesAsync(); } return(ResponseMODEL.Instance(true, "Transaccion Exitosa", "Editorial eliminada")); } catch (Exception ex) { return(ResponseMODEL.Instance(false, "Error Controlado", "Se controlo un error en la aplicacion. Ver detalle", ex.Message, ex)); } }
public async Task <ResponseMODEL> UpdateAsync(Book model) { try { using (LibraryContext db = new LibraryContext()) { db.Entry(model).State = EntityState.Modified; await db.SaveChangesAsync(); } return(ResponseMODEL.Instance(true, "Transaccion Exitosa", "Libro modificado")); } catch (Exception ex) { return(ResponseMODEL.Instance(false, "Error Controlado", "Se controlo un error en la aplicacion. Ver detalle", ex.Message, ex)); } }
public async Task <ResponseMODEL> InsertAsync(Book model) { try { using (LibraryContext db = new LibraryContext()) { db.Books.Add(model); await db.SaveChangesAsync(); } return(ResponseMODEL.Instance(true, "Transaccion Exitosa", "Libro registrado")); } catch (Exception ex) { return(ResponseMODEL.Instance(false, "Error Controlado", "Se controlo un error en la aplicacion. Ver detalle", ex.Message, ex)); } }
public async Task <ResponseMODEL> UpdateAsync(AuthorMODEL model) { try { Author modelDAL = new Author(); modelDAL.Email = model.Email; modelDAL.BirthDate = model.BirthDate; modelDAL.CityOrigin = model.CityOrigin; modelDAL.FullName = model.FullName; modelDAL.IdAuthor = model.IdAuthor; return(await authorDAL.UpdateAsync(modelDAL)); } catch (Exception ex) { return(ResponseMODEL.Instance(false, "Error Controlado", "Se controlo un error en la aplicacion.", ex.Message, ex)); } }
public async Task <ResponseMODEL> GetByIdAuthorAsync(int id) { try { using (LibraryContext db = new LibraryContext()) { var result = await db.Books .Where(i => i.IdAuthor == id) .ToListAsync(); return(ResponseMODEL.Instance(true, "Transaccion Exitosa", "Consulta exitosa a la tabla \"Libros\"", null, result)); } } catch (Exception ex) { return(ResponseMODEL.Instance(false, "Error Controlado", "Se controlo un error en la aplicacion. Ver detalle", ex.Message, ex)); } }
public async Task <ResponseMODEL> UpdateAsync(EditorialMODEL model) { try { Editorial modelDAL = new Editorial(); modelDAL.Email = model.Email; modelDAL.CorrespondenceAddress = model.CorrespondenceAddress; modelDAL.Phone = model.Phone; modelDAL.Name = model.Name; modelDAL.MaximumBooksRegistered = model.MaximumBooksRegistered; modelDAL.IdEditorial = model.IdEditorial; return(await editorialDAL.UpdateAsync(modelDAL)); } catch (Exception ex) { return(ResponseMODEL.Instance(false, "Error Controlado", "Se controlo un error en la aplicacion.", ex.Message, ex)); } }
public async Task <ResponseMODEL> GetAllAsync() { try { var resultProcess = await bookDAL.GetAllAsync(); if (resultProcess.IsApproved) { List <Book> result = (List <Book>)resultProcess.ObjectResult; if (result.Count == 0) { return(ResponseMODEL.Instance(true, "Consulta Exitosa", "Lista Vacia", "La tabla \"Libros\" esta vacia", result)); } else { var resultList = result.Select(i => new BookMODEL { IdBook = i.IdBook, Gender = i.Gender, IdAuthor = i.IdAuthor, IdEditorial = i.IdEditorial, NumberPages = i.NumberPages, Tittle = i.Tittle, Year = i.Year } ).ToList(); resultProcess.ObjectResult = null; resultProcess.ObjectResult = resultList; } } return(resultProcess); } catch (Exception ex) { return(ResponseMODEL.Instance(false, "Error Controlado", "Se controlo un error en la aplicacion.", ex.Message, ex)); } }
public async Task <ResponseMODEL> GetAllAsync() { try { var resultProcess = await editorialDAL.GetAllAsync(); if (resultProcess.IsApproved) { List <Editorial> result = (List <Editorial>)resultProcess.ObjectResult; if (result.Count == 0) { return(ResponseMODEL.Instance(true, "Consulta Exitosa", "Lista Vacia", "La tabla \"Editorial\" esta vacia", result)); } else { var resultList = result.Select(i => new EditorialMODEL { Email = i.Email, CorrespondenceAddress = i.CorrespondenceAddress, Phone = i.Phone, Name = i.Name, MaximumBooksRegistered = i.MaximumBooksRegistered, IdEditorial = i.IdEditorial } ).ToList(); resultProcess.ObjectResult = null; resultProcess.ObjectResult = resultList; } } return(resultProcess); } catch (Exception ex) { return(ResponseMODEL.Instance(false, "Error Controlado", "Se controlo un error en la aplicacion.", ex.Message, ex)); } }
public async Task <ResponseMODEL> DeleteAsync(int id) { try { var resultProcess = await editorialDAL.GetAsync(id); var validateBooks = await bookDAL.GetByIdEditorialAsync(id); if (!validateBooks.IsApproved) { return(resultProcess); } if (((List <Book>)validateBooks.ObjectResult).Count > 0) { return(ResponseMODEL.Instance(false, "Transaccion Rechazada", "Editorial con libros activos", "No puede eliminar una editorial si tiene libros activos")); } if (resultProcess.IsApproved) { if ((Editorial)resultProcess.ObjectResult != null) { return(await editorialDAL.DeleteAsync((Editorial)resultProcess.ObjectResult)); } else { return(ResponseMODEL.Instance(false, "Transaccion Rechazada", "No es posible eliminar la editorial", "No existe una editorial que coincida con el codigo enviado")); } } else { return(resultProcess); } } catch (Exception ex) { return(ResponseMODEL.Instance(false, "Error Controlado", "Se controlo un error en la aplicacion.", ex.Message, ex)); } }
public async Task <ResponseMODEL> GetAllAsync() { try { var resultProcess = await authorDAL.GetAllAsync(); if (resultProcess.IsApproved) { List <Author> result = (List <Author>)resultProcess.ObjectResult; if (result.Count == 0) { return(ResponseMODEL.Instance(true, "Consulta Exitosa", "Lista Vacia", "La tabla \"Autor\" esta vacia", result)); } else { var resultList = result.Select(i => new AuthorMODEL { Email = i.Email, BirthDate = i.BirthDate, CityOrigin = i.CityOrigin, FullName = i.FullName, IdAuthor = i.IdAuthor } ).ToList(); resultProcess.ObjectResult = null; resultProcess.ObjectResult = resultList; } } return(resultProcess); } catch (Exception ex) { return(ResponseMODEL.Instance(false, "Error Controlado", "Se controlo un error en la aplicacion.", ex.Message, ex)); } }
public async Task <ResponseMODEL> GetAsync(int id) { try { var resultProcess = await bookDAL.GetAsync(id); if (resultProcess.IsApproved) { Book result = (Book)resultProcess.ObjectResult; if (result == null) { return(ResponseMODEL.Instance(true, "Consulta Exitosa", "Sin resultados", "No existen coincidencias con para esta consulta", result)); } else { BookMODEL resultObject = new BookMODEL { IdBook = result.IdBook, Gender = result.Gender, IdAuthor = result.IdAuthor, IdEditorial = result.IdEditorial, NumberPages = result.NumberPages, Tittle = result.Tittle, Year = result.Year }; resultProcess.ObjectResult = null; resultProcess.ObjectResult = resultObject; } } return(resultProcess); } catch (Exception ex) { return(ResponseMODEL.Instance(false, "Error Controlado", "Se controlo un error en la aplicacion.", ex.Message, ex)); } }
public async Task <ResponseMODEL> GetAsync(int id) { try { var resultProcess = await editorialDAL.GetAsync(id); if (resultProcess.IsApproved) { Editorial result = (Editorial)resultProcess.ObjectResult; if (result == null) { return(ResponseMODEL.Instance(true, "Consulta Exitosa", "Sin resultados", "No existen coincidencias con para esta consulta", result)); } else { EditorialMODEL resultObject = new EditorialMODEL { Email = result.Email, CorrespondenceAddress = result.CorrespondenceAddress, Phone = result.Phone, Name = result.Name, MaximumBooksRegistered = result.MaximumBooksRegistered, IdEditorial = result.IdEditorial }; resultProcess.ObjectResult = null; resultProcess.ObjectResult = resultObject; } } return(resultProcess); } catch (Exception ex) { return(ResponseMODEL.Instance(false, "Error Controlado", "Se controlo un error en la aplicacion.", ex.Message, ex)); } }
public async Task <ResponseMODEL> GetAsync(int id) { try { var resultProcess = await authorDAL.GetAsync(id); if (resultProcess.IsApproved) { Author result = (Author)resultProcess.ObjectResult; if (result == null) { return(ResponseMODEL.Instance(true, "Consulta Exitosa", "Sin resultados", "No existen coincidencias con para esta consulta", result)); } else { AuthorMODEL resultObject = new AuthorMODEL { Email = result.Email, BirthDate = result.BirthDate, CityOrigin = result.CityOrigin, FullName = result.FullName, IdAuthor = result.IdAuthor }; resultProcess.ObjectResult = null; resultProcess.ObjectResult = resultObject; } } return(resultProcess); } catch (Exception ex) { return(ResponseMODEL.Instance(false, "Error Controlado", "Se controlo un error en la aplicacion.", ex.Message, ex)); } }
public async Task <ResponseMODEL> UpdateAsync(BookMODEL model) { try { var validateEditorial = await editorialDAL.GetAsync(model.IdEditorial); if (!validateEditorial.IsApproved) { return(validateEditorial); } Editorial editorial = (Editorial)validateEditorial.ObjectResult; if (editorial == null) { return(ResponseMODEL.Instance(false, "Transaccion Rechazada", "La editorial no está registrada", "Transaccion rechazada por regla de negocio")); } var validateAuthor = await authorDAL.GetAsync(model.IdAuthor); if (!validateAuthor.IsApproved) { return(validateAuthor); } Author author = (Author)validateAuthor.ObjectResult; if (author == null) { return(ResponseMODEL.Instance(false, "Transaccion Rechazada", "El autor no está registrado", "Transaccion rechazada por regla de negocio")); } var limit = editorial.MaximumBooksRegistered; var validateBooksEditorial = await bookDAL.GetByIdEditorialAsync(model.IdEditorial); if (validateBooksEditorial.IsApproved) { List <Book> booksEditorial = (List <Book>)validateBooksEditorial.ObjectResult; if (booksEditorial.Count < limit || limit == -1) { Book modelDAL = new Book(); modelDAL.IdBook = model.IdBook; modelDAL.Tittle = model.Tittle; modelDAL.Year = model.Year; modelDAL.NumberPages = model.NumberPages; modelDAL.Gender = model.Gender; modelDAL.IdAuthor = model.IdAuthor; modelDAL.IdEditorial = model.IdEditorial; return(await bookDAL.UpdateAsync(modelDAL)); } else { return(ResponseMODEL.Instance(false, "Transaccion Rechazada", "No es posible modificar el libro, se alcanzó el máximo permitido", "Transaccion rechazada por regla de negocio")); } } else { return(validateBooksEditorial); } } catch (Exception ex) { return(ResponseMODEL.Instance(false, "Error Controlado", "Se controlo un error en la aplicacion.", ex.Message, ex)); } }