Ejemplo n.º 1
0
        // GET: /Adverts/Details/id

        public ActionResult Details(int?id)
        {
            if (id != null)
            {
                displayRepository.AdvertDetails = advertRepository.GetDetails((int)id);
                displayRepository.Images        = advertRepository.GetAdImages((int)id);
                // var login = Convert.ToInt32(Session["Login"]);
                if (Session["ID"] != null)
                {
                    int uID = Convert.ToInt32(Session["ID"]);
                    displayRepository.LoggedUser = advertRepository.GetUserData(uID);
                    displayRepository.FAV        = db.FAV.SingleOrDefault(x => x.ADV == id && x.USER == uID);
                }
                if (displayRepository.AdvertDetails == null)
                {
                    return(HttpNotFound());
                }
                else
                {
                    return(View("Details", displayRepository));
                }
            }
            return(RedirectToAction("Wyszukiwanie", "Home"));
        }
Ejemplo n.º 2
0
        public ActionResult Wyszukiwanie(int?page, string search, string sortOrder, string currentFilter)
        {
            if (Session["ID"] != null)
            {
                int uID = Convert.ToInt32(Session["ID"]);
                displayAdsRepository.LoggedUser = advertRepository.GetUserData(uID);
                displayAdsRepository.FavUsera   = advertRepository.GetUserFav(uID);
            }
            ViewBag.CurrentSort   = sortOrder;
            ViewBag.NameSortParm  = sortOrder == "name" ? "name_desc" : "name";
            ViewBag.DateSortParm  = sortOrder == "Date" ? "date_desc" : "Date";
            ViewBag.PriceSortParm = sortOrder == "Price" ? "Price_desc" : "Price";
            if (search != null)
            {
                page = 1;
            }
            else
            {
                search = currentFilter;
            }
            ViewBag.CurrentFilter = search;
            var adverts = db.ADVERTS.Where(x => x.IS_ARCHIVED == false);

            if (!String.IsNullOrEmpty(search))
            {
                adverts = adverts.Where(s => s.IS_ARCHIVED == false && ((s.TITLE.Contains(search)) || (s.DESCRIPTION.Contains(search))));
            }
            else if (String.IsNullOrEmpty(search))
            {
                adverts = adverts.Where(s => s.IS_ARCHIVED == false);
            }
            switch (sortOrder)
            {
            case "name_desc":
                adverts = adverts.OrderByDescending(s => s.TITLE);
                break;

            case "name":
                adverts = adverts.OrderBy(s => s.TITLE);
                break;

            case "Price":
                adverts = adverts.OrderBy(s => s.PRICE);
                break;

            case "Price_desc":
                adverts = adverts.OrderByDescending(s => s.PRICE);
                break;

            case "Date":
                adverts = adverts.OrderBy(s => s.DATE);
                break;

            case "date_desc":
                adverts = adverts.OrderByDescending(s => s.DATE);
                break;

            default:
                adverts = adverts.OrderByDescending(s => s.DATE);
                break;
            }
            int pageSize   = 10;
            int pageNumber = (page ?? 1);

            displayAdsRepository.ADVERTS = adverts.ToPagedList(pageNumber, pageSize);
            displayAdsRepository.IMAGES  = new AdvertRepository().GetAdsImages().ToList();;
            return(View(displayAdsRepository));
        }