public void borrow(string userId, string title, string branchname)
        {
            Borrow borrow = new Borrow();

            borrow.Amount   = 1;
            borrow.BookId   = _bookService.GetBooksByCondition(b => b.Title == title).First().BookId;
            borrow.BranchId = _branchService.GetBranchByCondition(b => b.Name == branchname).First().BranchId;
            borrow.UserId   = userId;

            repositoryWrapper.BorrowRepository.Create(borrow);
        }
Ejemplo n.º 2
0
        public StockModel GetStockModelByBranchId(int branchId)
        {
            StockModel   stock     = new StockModel();
            List <Stock> stock_raw = GetStockByCondition(b => b.BranchId == branchId);

            stock.LibraryName = _branchService.GetBranchByCondition(b => b.BranchId == branchId).FirstOrDefault().Name;

            foreach (var br_stock in stock_raw)
            {
                string title    = _bookService.GetBooksByCondition(b => b.BookId == br_stock.BookId).FirstOrDefault().Title;
                int    quantity = br_stock.Quantity;
                stock.Stock.Add(new StockModel.pair(title, quantity));
            }
            return(stock);
        }
        public List <BranchModel> GetBranchesModelContainingBook(string title)
        {
            Book         book        = _bookService.GetBooksByCondition(b => b.Title == title).First();
            List <Stock> stocks      = repositoryWrapper.StockRepository.FindByCondition(b => b.BookId == book.BookId).ToList();
            List <int>   branches_id = new List <int>();

            foreach (Stock stock in stocks)
            {
                if (stock.Quantity > 0)
                {
                    branches_id.Add(stock.BranchId);
                }
            }
            branches_id = branches_id.Distinct().ToList();

            List <BranchModel> branches = new List <BranchModel>();

            foreach (int id in branches_id)
            {
                Branch      branch       = GetBranchByCondition(b => b.BranchId == id).First();
                BranchModel branch_model = new BranchModel();
                branch_model.Name     = branch.Name;
                branch_model.Location = branch.Location;
                branches.Add(branch_model);
            }
            return(branches);
        }
        public StockModel GetStockModelByBranchId(int branchId)
        {
            StockModel   stock     = new StockModel();
            List <Stock> stock_raw = GetStockByCondition(b => b.BranchId == branchId);

            stock.LibraryName = _branchService.GetBranchByCondition(b => b.BranchId == branchId).FirstOrDefault().Name;

            foreach (Stock br_stock in stock_raw)
            {
                try //do not remove the try/catch statement, error trown for no apparent reason
                {
                    string title    = _bookService.GetBooksByCondition(b => b.BookId == br_stock.BookId).FirstOrDefault().Title;
                    int    quantity = br_stock.Quantity;
                    stock.Stock.Add(new StockModel.pair(title, quantity));
                }
                catch
                {
                    return(stock);
                }
            }
            return(stock);
        }