Exemple #1
0
        public ActionResult Invites(int id = 1)
        {
            HttpCookie cookie = Request.Cookies[FormsAuthentication.FormsCookieName];
            FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);
            string username = ticket.Name;
            List<ShortTrip> trips = new List<ShortTrip>();

            using (var db = new RazomContext())
            {
                Users user = db.Users.Where(u => u.Login == username).FirstOrDefault();
                trips = (from tr in db.Travels
                         join inv in db.Invite on tr.TravelID equals inv.TravelID
                         join u in db.Users on inv.UserID equals u.UserID
                         where u.UserID == user.UserID
                         select new ShortTrip
                         {
                             Date = tr.DateFinish < DateTime.Now ? "Минула" : (tr.DateStart > DateTime.Now ? "Буде в майбутньому" : "Відбувається зараз"),
                             ID = tr.TravelID,
                             Name = tr.Name
                         }).ToList();
            }

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

            trips = trips.Skip((id - 1) * pageSize).Take(pageSize).ToList();
            TripCollection tc = new TripCollection { Trips = trips, CurrentPage = id, PagesCount = pCount, IncomingInvites = false };

            return View(tc);
        }
Exemple #2
0
        public ActionResult PastTrips(int id = 1)
        {
            List<ShortTrip> result = new List<ShortTrip>();
            bool invites = false;
            using (var db = new RazomContext())
            {
                result = (from t in db.Travels
                          join h in db.History on t.TravelID equals h.TravelID
                          where t.DateFinish < DateTime.Now
                          select new ShortTrip
                          {
                              Date = "Минула",
                              Name = t.Name,
                              ID = t.TravelID
                          }).ToList();
                HttpCookie cookie = Request.Cookies[FormsAuthentication.FormsCookieName];
                FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);
                int user = db.Users.Where(u => u.Login == ticket.Name).SingleOrDefault().UserID;

                if (db.Invite.Where(i => i.UserID == user).Count() > 0)
                {
                    invites = true;
                }
            }
            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((id - 1) * pageSize).Take(pageSize).ToList();
            TripCollection tc = new TripCollection() { Trips = list, PagesCount = pCount, CurrentPage = id, IncomingInvites = invites, ActionUrl = "PastTrips" };
            return View("Index", tc);
        }
Exemple #3
0
        public ActionResult Index(int id = 1)
        {
            List<ShortTrip> result = new List<ShortTrip>();
            bool invites = false;
            using(var db = new RazomContext())
            {
                HttpCookie cookie = Request.Cookies[FormsAuthentication.FormsCookieName];
                FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);
                int user = db.Users.Where(u => u.Login == ticket.Name).SingleOrDefault().UserID;

                result = (from t in db.Travels
                          join h in db.History on t.TravelID equals h.TravelID
                          where h.UserID == user
                          select new ShortTrip
                        {
                            Date = t.DateFinish < DateTime.Now ? "Минула" : (t.DateStart > DateTime.Now ? "Буде в майбутньому" : "Відбувається зараз"),
                            Name = t.Name,
                            ID = t.TravelID
                        }).ToList();

                foreach (var item in result)
                {
                    var photos = (from pp in db.PhotosPlace
                                             join pl in db.Places on pp.PlaceID equals pl.PlaceID
                                             join tp in db.TravelPlaces on pl.PlaceID equals tp.PlaceID
                                             where tp.TravelID == item.ID
                                             select pp);
                    PhotosPlace photo = photos.Count() != 0 ? photos.First() : null;
                    item.PhotoFile = photo != null ? photo.FotoID : 0;
                    item.PhotoUrl = photo != null ? photo.href : null;
                    item.PlacesCount = (from tp in db.TravelPlaces
                                        join tr in db.Travels on tp.TravelID equals tr.TravelID
                                        where tr.TravelID == item.ID
                                        select new {tr_id = tr.TravelID, tp_id = tp.TravelID}).Count();
                    item.MembersCount = (from h in db.History
                                         join tr in db.Travels on h.TravelID equals tr.TravelID
                                         where tr.TravelID == item.ID
                                         select new { tr_id = tr.TravelID, u_id = h.HistoryID }).Count();
                }

                if (db.Invite.Where( i => i.UserID == user).Count() > 0)
                {
                    invites = true;
                }
            }
            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((id - 1) * pageSize).Take(pageSize).ToList();
            TripCollection tc = new TripCollection() { Trips = list, PagesCount = pCount, CurrentPage = id, IncomingInvites = invites, ActionUrl="Index"};
            return View(tc);
        }