Пример #1
0
        // GET: Orders/Create
        public IActionResult Create()
        {
            if (HelperUser.isAdministrator(this.User.Identity.Name))
            {
                ViewData["BookId"] = new SelectList(_context.Book, "BookId", "ISBN");
                ViewData["UserId"] = new SelectList(_context.User, "UserId", "CreditcardName");
                return(View());
            }

            return(RedirectToAction("Index"));
        }
Пример #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()));
        }
Пример #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()));
        }
Пример #4
0
        // GET: Orders/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (!HelperUser.isAdministrator(this.User.Identity.Name))
            {
                return(RedirectToAction("Index"));
            }

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

            var order = await _context.Order.FindAsync(id);

            if (order == null)
            {
                return(NotFound());
            }
            ViewData["BookId"] = new SelectList(_context.Book, "BookId", "ISBN", order.BookId);
            ViewData["UserId"] = new SelectList(_context.User, "UserId", "CreditcardName", order.UserId);
            return(View(order));
        }
Пример #5
0
        // GET: Orders/Delete/5
        public async Task <IActionResult> Delete(int?id)
        {
            if (!HelperUser.isAdministrator(this.User.Identity.Name))
            {
                return(RedirectToAction("Index"));
            }

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

            var order = await _context.Order
                        .Include(o => o.Book)
                        .Include(o => o.User)
                        .FirstOrDefaultAsync(m => m.OrderId == id);

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

            return(View(order));
        }
Пример #6
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)));
        }