public static bool Delete(int idLocation) { using (var _dbContext = new serti_dbContext()) { var locationFiltered = _dbContext.Location.FirstOrDefault(_location => _location.Id == idLocation); if (locationFiltered == null) { return(false); } _dbContext.Remove(locationFiltered); return(_dbContext.SaveChanges() > 0); } }
public static bool Delete(int idBook) { using (var _dbContext = new serti_dbContext()) { var bookFiltered = _dbContext.Book.FirstOrDefault(_book => _book.Id == idBook); if (bookFiltered == null) { return(false); } _dbContext.Remove(bookFiltered); return(_dbContext.SaveChanges() > 0); } }
public static bool Create(BookViewModel bookViewModel) { using (var _dbContext = new serti_dbContext()) { var book = new Book() { IdLocation = (int)bookViewModel.LocationViewModel.Id, VolumeNumber = bookViewModel.VolumeNumber, Title = bookViewModel.Title, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }; _dbContext.Book.Add(book); return(_dbContext.SaveChanges() > 0); } }
public static bool Create(LocationViewModel locationViewModel) { using (var _dbContext = new serti_dbContext()) { var location = new Location() { Shelf = locationViewModel.Shelf, Room = locationViewModel.Room, Bookseller = locationViewModel.Bookseller, Position = locationViewModel.Position, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }; _dbContext.Location.Add(location); return(_dbContext.SaveChanges() > 0); } }
public static bool Update(BookViewModel bookViewModel) { using (var _dbContext = new serti_dbContext()) { var bookFiltered = _dbContext.Book.FirstOrDefault(_book => _book.Id == bookViewModel.Id); if (bookFiltered == null) { return(false); } bookFiltered.VolumeNumber = bookViewModel.VolumeNumber; bookFiltered.Title = bookFiltered.Title; bookFiltered.UpdatedAt = DateTime.Now; return(_dbContext.SaveChanges() > 0); } }
public static bool Update(LocationViewModel locationViewModel) { using (var _dbContext = new serti_dbContext()) { var locationFiltered = _dbContext.Location.FirstOrDefault(_location => _location.Id == locationViewModel.Id); if (locationFiltered == null) { return(false); } locationFiltered.Shelf = locationViewModel.Shelf; locationFiltered.Room = locationViewModel.Room; locationFiltered.Bookseller = locationViewModel.Bookseller; locationFiltered.Position = locationViewModel.Position; locationFiltered.UpdatedAt = DateTime.Now; return(_dbContext.SaveChanges() > 0); } }