Exemple #1
0
        public ActionResult PagerPlaceSearch(FormCollection form)
        {
            string id = form["id"].ToString();
            int page = int.Parse(form["page"].ToString());
            List<ShortPlace> result = getSearchList(id);
            int pageSize = 6;
            int pCount = 0;
            if (result.Count % pageSize == 0)
            {
                pCount = result.Count / pageSize;
            }
            else
                pCount = result.Count / pageSize + 1;

            var list = result.Skip((page - 1) * pageSize).Take(pageSize).ToList();
            PlaceCollection pc = new PlaceCollection() { Places = list, CurrentPage = page, PagesCount = pCount, Info = id };
            return View("PlaceSearch", pc);
        }
Exemple #2
0
        public ActionResult PlaceSearch(string id = "", int page = 1)
        {
            if (id != "")
            {
                List<ShortPlace> result = getSearchList(id);

                int pageSize = 6;
                int pCount = 0;
                if (result.Count % pageSize == 0)
                {
                    pCount = result.Count / pageSize;
                }
                else
                    pCount = result.Count / pageSize + 1;
                var list = result.Take(pageSize).ToList();
                PlaceCollection pc = new PlaceCollection() { Places = list, CurrentPage = page, PagesCount = pCount, Info=id};
                return View(pc);
            }
            return View();
        }
Exemple #3
0
        public ActionResult Index(int id = 1)
        {
            List<ShortPlace> result = new List<ShortPlace>();
            using (var con = new RazomContext())
            {
                HttpCookie cookie = Request.Cookies[FormsAuthentication.FormsCookieName];
                FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);
                string username = ticket.Name;
                int userID = con.Users.SingleOrDefault(u => u.Login == username).UserID;
                result = (from pl in con.Places
                         join fpl in con.FuturePlace on pl.PlaceID equals fpl.PlaceID
                         //join u in con.Users on fpl.UserID equals u.UserID
                         //join p in con.PhotosPlace on pl.PlaceID equals p.PlaceID into gj
                         where fpl.UserID == userID
                         //from subres in gj.DefaultIfEmpty()
                         select new ShortPlace
                         {
                             ID = fpl.ID,
                             Name = pl.Name,
                             Rating = pl.Rating ?? 0,
                             PlaceID = pl.PlaceID,
                             //PhotoUrl = subres == null ? " ": subres.href,
                             //PhotoByte = subres.FotoID,
                             City = con.Region.FirstOrDefault(r => r.CityID == pl.CityID).Name,
                             PlaceType = con.PlaceType.FirstOrDefault(pt => pt.PlaceTypeID == pl.PlaceTypeID).Type
                         }).ToList();

                result.ForEach(r =>
                {
                    var photo = con.PhotosPlace.Where(pp => pp.PlaceID == r.PlaceID);
                    if (photo != null)
                    {
                        if (photo.First().FileFoto != null)
                        {
                            r.PhotoByte = photo.First().FotoID;
                        }
                        else
                            if (photo.First().href != null )
                            {
                                r.PhotoUrl = photo.First().href;
                            }
                    }

                    r.tags = (from t in con.Tag
                              join ttp in con.TagToPlace on t.TagID equals ttp.TagID
                              where ttp.PlaceID == r.PlaceID
                              select t.NameTag).ToList();
                });
            }

            int pageSize = 6;
            int pCount = 0;
            if(result.Count % pageSize == 0)
            {
                pCount = result.Count / pageSize;
            }
            else
                pCount = result.Count / pageSize + 1;

            List<ShortPlace> list = result.OrderBy(p => p.Name).Skip((id - 1) * pageSize).Take(pageSize).ToList();
            PlaceCollection pc = new PlaceCollection() { Places = list, CurrentPage = id, PagesCount = pCount };
            return View(pc);
        }