Exemple #1
0
        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);
            }
        }
Exemple #2
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);
            }
        }
Exemple #3
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);
            }
        }
Exemple #4
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);
            }
        }
Exemple #5
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);
            }
        }
Exemple #6
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);
            }
        }
Exemple #7
0
        public static List <LocationViewModel> Get()
        {
            using (var _dbContext = new serti_dbContext())
            {
                var locations = _dbContext.Location.AsQueryable();

                //if(filter != null)
                //{
                //    if (filter.Id != null)
                //        locations = locations.Where(location => location.Id == filter.Id);
                //}

                var locationsVm = locations.Select(location => new LocationViewModel
                {
                    Id         = location.Id,
                    Shelf      = location.Shelf,
                    Room       = location.Room,
                    Bookseller = location.Bookseller,
                    Position   = location.Position
                }).ToList();

                return(locationsVm);
            }
        }
Exemple #8
0
        public static List <BookViewModel> Get()
        {
            using (var _dbContext = new serti_dbContext())
            {
                var books = _dbContext.Book.AsQueryable();

                var booksVm = books.Select(book => new BookViewModel
                {
                    Id = book.Id,
                    LocationViewModel = new LocationViewModel
                    {
                        Id         = book.IdLocationNavigation.Id,
                        Shelf      = book.IdLocationNavigation.Shelf,
                        Room       = book.IdLocationNavigation.Room,
                        Bookseller = book.IdLocationNavigation.Bookseller,
                        Position   = book.IdLocationNavigation.Position
                    },
                    VolumeNumber = book.VolumeNumber,
                    Title        = book.Title,
                }).ToList();

                return(booksVm);
            }
        }