Beispiel #1
0
        // GET: Orders/Create
        public async Task <IActionResult> BuyIt(int id = 0)
        {
            Order order = new Order();

            if (id == 0)
            {
                return(NotFound());
            }

            var book = _context.Book.Include(b => b.BookCondition).Include(b => b.StudyArea).Where(b => b.BookId == id).First();

            if (book == null)
            {
                return(NotFound());
            }

            order.BookId       = id;
            order.CreationDate = DateTime.Now;
            order.PaymentForm  = "c";
            order.Price        = book.Price;
            order.Quantity     = 1;
            order.SellerId     = book.UserId;
            order.UserId       = HelperUser.GetUserId(this.User.Identity.Name, _context);

            ViewData["BookTitle"]     = book.Title;
            ViewData["StudyArea"]     = book.StudyArea.StudyAreaName;
            ViewData["BookCondition"] = book.BookCondition.Condition;
            ViewData["MaxQty"]        = book.Quantity;

            //ViewData["BookId"] = new SelectList(_context.Book, "BookId", "ISBN", order.BookId);
            //ViewData["UserId"] = new SelectList(_context.User, "UserId", "CreditcardName", order.UserId);
            return(View(order));
        }
Beispiel #2
0
        public async Task <IActionResult> Index()
        {
            int UserId        = HelperUser.GetUserId(this.User.Identity.Name, _context);
            var seboDbContext = _context.Book.Include(b => b.BookCondition)
                                .Include(b => b.StudyArea)
                                .Include(b => b.User)

                                .Where(b => HelperUser.isAdministrator(this.User.Identity.Name) || String.IsNullOrEmpty(this.User.Identity.Name) ? b.UserId > 0 : b.UserId != UserId)
                                .Where(b => b.Quantity > b.QuantitySold);

            return(View(await seboDbContext.ToListAsync()));
        }
Beispiel #3
0
        // GET: Orders
        public async Task <IActionResult> Index()
        {
            int userId = HelperUser.GetUserId(this.User.Identity.Name, _context);

            var seboDbContext = _context.Order.Include(o => o.Book).Include(o => o.User)
                                .Where(o =>
                                       HelperUser.isAdministrator(this.User.Identity.Name)? o.UserId > 0 : o.UserId == userId ||
                                       HelperUser.isAdministrator(this.User.Identity.Name) ? o.SellerId > 0 : o.SellerId == userId
                                       );

            return(View(await seboDbContext.ToListAsync()));
        }
Beispiel #4
0
        // GET: Books
        public async Task <IActionResult> BooksCatalog(string UserName, string sortOrder, string currentSearchString, string SearchString, int StudyAreaFilter, int BookConditionFilter, int?Page)
        {
            if (currentSearchString != null)
            {
                string[] m = currentSearchString.Split(".");
                currentSearchString = m[0]; // preserves the current filter typed within the search textbox
                if (SearchString == null)
                {
                    SearchString = currentSearchString;
                }
                if (StudyAreaFilter == 0)
                {
                    StudyAreaFilter = Int32.Parse(m[1]);   // preserves the select institution option in the dropdownlist
                }
                if (BookConditionFilter == 0)
                {
                    BookConditionFilter = Int32.Parse(m[2]);     // preserves the select Study Area option in the dropdownlist
                }
            }
            //Get the User ID
            int UserId       = HelperUser.GetUserId(this.User.Identity.Name, _context);
            int UserBranchId = HelperUser.GetUserBranchId(this.User.Identity.Name, _context);

            // Cheks whether a search string was typed and prepares for search by each word
            string[] myString = SearchString != null?SearchString.Trim().Split(" ") : new string[0];

            // Get the seach's recordset already sorted
            var books = StringSearch.SearchBook(_context, sortOrder, myString).Include(b => b.BookCondition).Include(b => b.StudyArea).Include(b => b.User)
                        .Where(b => !b.Blocked)
                        .Where(b => b.Quantity > b.QuantitySold)
                        .Where(b => b.UserId != UserId)
                        .Where(b => !b.IsWaitList);

            var users = (from u in _context.User select u).Include(u => u.InstitutionBranch);
            //Getting the books from the same institution
            var books2 = (from b in books
                          join u in users on b.UserId equals u.UserId
                          select new
            {
                b.Blocked,
                b.BookCondition,
                b.BookConditionId,
                b.BookId,
                b.CreationDate,
                b.Description,
                b.Edition,
                b.ISBN,
                b.IsWaitList,
                b.Orders,
                b.PhotoFileName,
                b.Price,
                b.Publisher,
                b.Quantity,
                b.QuantitySold,
                b.StudyArea,
                b.StudyAreaId,
                b.Title,
                b.User,
                b.UserId,
                b.Visualizations,
                u.InstitutionBranchId,
                u.InstitutionBranch.InstitutionBranchName
            }).Where(b => b.InstitutionBranchId == UserBranchId);

            // Applying filters on the table
            if (StudyAreaFilter != 0)
            {
                books2 = books2.Where(b => b.StudyAreaId == StudyAreaFilter);
            }
            if (BookConditionFilter != 0)
            {
                books2 = books2.Where(b => b.BookConditionId == BookConditionFilter);
            }

            //
            // Preparing Dropboxes
            //
            var StudyAreas     = (from s in books2 orderby s.StudyArea.StudyAreaName select new { s.StudyAreaId, s.StudyArea.StudyAreaName }).ToList().Distinct();
            var BookConditions = (from b in books2 orderby b.BookCondition select new { b.BookConditionId, b.BookCondition.Condition }).ToList().Distinct();

            ViewData["StudyAreaFilter"]     = new SelectList(StudyAreas, "StudyAreaId", "StudyAreaName");
            ViewData["BookConditionFilter"] = new SelectList(BookConditions, "BookConditionId", "Condition");
            //////////////////////////////////////

            ViewData["CurrentSearchString"] = SearchString + "." + StudyAreaFilter + "." + BookConditionFilter + "." + Page;
            ViewData["SearchString"]        = SearchString;

            //
            // Just tracking which ordering column was trigged for setting the actual ordering
            //
            ViewData["Title"]         = OrderingBooks.NewOrder(sortOrder, "Title");
            ViewData["StudyArea"]     = OrderingBooks.NewOrder(sortOrder, "StudyArea");
            ViewData["BookCondition"] = OrderingBooks.NewOrder(sortOrder, "BookCondition");
            ViewData["ISBN"]          = OrderingBooks.NewOrder(sortOrder, "ISBN");
            ViewData["Price"]         = OrderingBooks.NewOrder(sortOrder, "Price");

            int PageSize = 14;

            return(View(await Pagination <Book> .CreateAsync(books.AsNoTracking(), Page ?? 1, PageSize)));
        }
Beispiel #5
0
        public async Task <IActionResult> Index(string UserName, string sortOrder, string currentSearchString, string SearchString, int StudyAreaFilter, int BookConditionFilter, int?Page)
        {
            if (currentSearchString != null)
            {
                string[] m = currentSearchString.Split(".");
                currentSearchString = m[0]; // preserves the current filter typed within the search textbox
                if (SearchString == null)
                {
                    SearchString = currentSearchString;
                }
                if (StudyAreaFilter == 0)
                {
                    StudyAreaFilter = Int32.Parse(m[1]);   // preserves the select institution option in the dropdownlist
                }
                if (BookConditionFilter == 0)
                {
                    BookConditionFilter = Int32.Parse(m[2]);     // preserves the select Study Area option in the dropdownlist
                }
            }
            //Get the User ID
            if (String.IsNullOrEmpty(UserName))
            {
                UserName = this.User.Identity.Name;
            }
            int UserId = HelperUser.GetUserId(UserName, _context);

            // Cheks whether a search string was typed and prepares for search by each word
            string[] myString = SearchString != null?SearchString.Trim().Split(" ") : new string[0];

            var x = HelperUser.isAdministrator(UserName);
            // Get the seach's recordset already sorted applying filtering according to user role
            var books = StringSearch.SearchBook(_context, sortOrder, myString).Include(b => b.BookCondition).Include(b => b.StudyArea).Include(b => b.User)
                        .Where(b => !b.Blocked)
                        .Where(b => b.Quantity > b.QuantitySold)
                        .Where(b => !b.IsWaitList)
                        .Where(b => HelperUser.isAdministrator(UserName) ? b.UserId > 0 : b.UserId == UserId);

            //.Where(b => UserId > 0 || UserName != null ? b.UserId == UserId : b.UserId > 0)

            // Applying filters on the table
            if (StudyAreaFilter != 0)
            {
                books = books.Where(b => b.StudyAreaId == StudyAreaFilter);
            }
            if (BookConditionFilter != 0)
            {
                books = books.Where(b => b.BookConditionId == BookConditionFilter);
            }

            //
            // Preparing Dropboxes
            //
            var StudyAreas     = (from s in books orderby s.StudyArea.StudyAreaName select new { s.StudyAreaId, s.StudyArea.StudyAreaName }).ToList().Distinct();
            var BookConditions = (from b in books orderby b.BookCondition select new { b.BookConditionId, b.BookCondition.Condition }).ToList().Distinct();

            ViewData["StudyAreaFilter"]     = new SelectList(StudyAreas, "StudyAreaId", "StudyAreaName");
            ViewData["BookConditionFilter"] = new SelectList(BookConditions, "BookConditionId", "Condition");
            //////////////////////////////////////

            ViewData["CurrentSearchString"] = SearchString + "." + StudyAreaFilter + "." + BookConditionFilter + "." + Page;
            ViewData["SearchString"]        = SearchString;

            //
            // Just tracking which ordering column was trigged for setting the actual ordering
            //
            ViewData["Title"]         = OrderingBooks.NewOrder(sortOrder, "Title");
            ViewData["StudyArea"]     = OrderingBooks.NewOrder(sortOrder, "StudyArea");
            ViewData["BookCondition"] = OrderingBooks.NewOrder(sortOrder, "BookCondition");
            ViewData["ISBN"]          = OrderingBooks.NewOrder(sortOrder, "ISBN");
            ViewData["Price"]         = OrderingBooks.NewOrder(sortOrder, "Price");

            int PageSize = 14;

            return(View(await Pagination <Book> .CreateAsync(books.AsNoTracking(), Page ?? 1, PageSize)));
        }