public ActionResult Account(int id) { Users user = new Users(); using (var db = new RazomContext()) { user = db.Users.Find(id); if (user == null) { return View("Error", new HandleErrorInfo(new Exception("Користувача не знайдено!"),"Account","Account")); } NetworkAccounts fs = db.NetworkAccounts.Where(i => i.NetworkID == db.Network.FirstOrDefault(j => j.Name == "foursquare").NetworkID).FirstOrDefault(i => i.UserID == user.UserID); NetworkAccounts tw = db.NetworkAccounts.Where(i => i.NetworkID == db.Network.FirstOrDefault(j => j.Name == "twitter").NetworkID).FirstOrDefault(i => i.UserID == user.UserID); NetworkAccounts vk = db.NetworkAccounts.Where(i => i.NetworkID == db.Network.FirstOrDefault(j => j.Name == "vk").NetworkID).FirstOrDefault(i => i.UserID == user.UserID); AccountModel a = new AccountModel() { ID = user.UserID, Login = user.Login, FirstName = user.FirstName ?? "", SecondName = user.SecondName ?? "", EMail = user.Email ?? "", Phone = user.Phone ?? "", FoursquareAccount = fs != null ? fs.ProfileURL : "", TwitterAccount = tw != null ? tw.ProfileURL : "", VKAccount = vk != null ? vk.ProfileURL : "", Associations = db.UsersData.Where(d => d.UserID == user.UserID && d.DataTypeID == db.DataType.Where(dt => dt.Type == "AboutMe").FirstOrDefault().DataTypeID).Select(t => t.Data).ToList() }; return View(a); } }
public ActionResult Create(PlaceCreator model, HttpPostedFileBase[] files) { int res = 0; if (ModelState.IsValid) { if (files.Count() > 5) { return Create("Не можна додавати більше 5 фото"); } using (var db = new RazomContext()) { Places p = new Places() { CityID = model.SelectedCity, Name = model.Place.Name, PlaceTypeID = model.SelectedPlaceType, Address = model.Place.Address, }; db.Places.Add(p); db.SaveChanges(); res = p.PlaceID; foreach (var file in files) { byte[] image = new byte[file.ContentLength]; using (BinaryReader r = new BinaryReader(file.InputStream)) { image = r.ReadBytes(file.ContentLength); } db.Database.ExecuteSqlCommand("INSERT INTO PhotosPlace(PlaceID,FileFoto) Values({0},{1})", p.PlaceID, image); } } return RedirectToAction("Show", "Place", new { id = res }); } return Create("Не введена назва або адреса"); }
public ActionResult AddComment(FormCollection form) { int id = int.Parse(form["id"].ToString()); string comment = form["comment"].ToString(); using (var db = new RazomContext()) { Comments c = new Comments { PlaceID = id, Message = comment }; db.Comments.Add(c); db.SaveChanges(); } return RedirectToAction("Show", new { id=id}); }
public ActionResult Create(string message="") { if (message != "") { ModelState.AddModelError(String.Empty,message); } PlaceCreator p = new PlaceCreator(); p.Place = new FullPlace(); using(var db = new RazomContext()) { p.PlaceTypes = new SelectList(db.PlaceType.OrderBy(m => m.Type).ToList(),"PlaceTypeID","Type"); p.Cities = new SelectList(db.Region.OrderBy(m => m.Name).Where(m => m.Name != "Невідомо").ToList(), "CityID", "Name"); } return View(p); }
public ActionResult AddUser(PeopleAddForm model) { List<AccountModel> people = new List<AccountModel>(); using (var db = new RazomContext()) { List<KeyValuePair<int,List<string>>> peopleIDs = PeopleSearchEngine.PeopleSearchEngine.GetSearchResultIndexes(model.Token); List<int> peopleInThisTrip = (from u in db.Users join h in db.History on u.UserID equals h.UserID join tr in db.Travels on h.TravelID equals tr.TravelID where tr.TravelID == model.TripID select u.UserID).ToList(); List<int> invitedPeople = (from u in db.Users join inv in db.Invite on u.UserID equals inv.UserID join tr in db.Travels on inv.TravelID equals tr.TravelID where tr.TravelID == model.TripID select u.UserID).ToList(); foreach (var item in peopleIDs) { if (!(peopleInThisTrip.Contains(item.Key) || invitedPeople.Contains(item.Key))) { people.Add(db.Users.Where(u => u.UserID == item.Key).Select(u => new AccountModel { Login = u.Phone, ID = u.UserID, FirstName = u.FirstName, SecondName = u.SecondName, EMail = u.Email, Phone = u.Phone, Associations = item.Value }).FirstOrDefault()); } } } int pageSize = 6; int pCount = 0; if (people.Count % pageSize == 0) { pCount = people.Count / pageSize; } else pCount = people.Count / pageSize + 1; people = people.Take(pageSize).ToList(); PeopleAddForm paf = new PeopleAddForm() { Token = model.Token, TripID = model.TripID, AccountsInfo = new AccountCollection() { Accounts=people, CurrentPage=1, PagesCount=pCount } }; return View(paf); }
public ActionResult AddToFavorite(int id) { HttpCookie cookie = Request.Cookies[FormsAuthentication.FormsCookieName]; FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value); string username = ticket.Name; using (var db = new RazomContext()) { Users user = db.Users.SingleOrDefault(u => u.Login == username); var set = db.FuturePlace.Where(p => p.PlaceID == id && p.UserID == user.UserID); if (set.Count() == 0) { FuturePlace p = new FuturePlace { PlaceID = id, UserID = user.UserID }; db.FuturePlace.Add(p); db.SaveChanges(); } } return RedirectToAction("Show", "Place", new { id=id}); }
public void Send(int user_id, int travel_id, string message) { string name = ""; using (var db = new RazomContext()) { Users u = db.Users.Find(user_id); name = u.FirstName + " " + u.SecondName; Message m = new Message { Time = DateTime.Now, TravelID = travel_id, UserID = user_id, Text = message }; db.Message.Add(m); db.SaveChanges(); } Clients.All.addNewMessageToPage(name, travel_id, message); }
public ActionResult AddPlace(PlaceAddForm model) { List<ShortPlace> places = new List<ShortPlace>(); using (var db = new RazomContext()) { PlaceSearchEngine.PlaceSearchEngine engine = new PlaceSearchEngine.PlaceSearchEngine(); List<int> placeIDs = engine.searchPlaces(model.Token); List<int> placeInThisTrip = (from pl in db.Places join tp in db.TravelPlaces on pl.PlaceID equals tp.PlaceID join tr in db.Travels on tp.TravelID equals tr.TravelID where tr.TravelID == model.TripID select pl.PlaceID).ToList(); foreach (var item in placeIDs) { if (!placeInThisTrip.Contains(item)) { places.Add(db.Places.Where(p => p.PlaceID == item).Select(p => new ShortPlace { ID = p.PlaceID, Name = p.Name }).FirstOrDefault()); } } } int pageSize = 6; int pCount = 0; if (places.Count % pageSize == 0) { pCount = places.Count / pageSize; } else pCount = places.Count / pageSize + 1; places = places.Take(pageSize).ToList(); PlaceAddForm paf = new PlaceAddForm() { Token = model.Token, TripID = model.TripID, PlacesInfo = new PlaceCollection() { Places = places, CurrentPage = 1, PagesCount = pCount } }; return View(paf); }
public ActionResult DeleteFromList(int id) { using (var db = new RazomContext()) { FuturePlace ID = db.FuturePlace.Find(id); if (ID != null) { db.FuturePlace.Remove(ID); db.SaveChanges(); ViewBag.Message = "Місце успішно видалено зі списку!"; return View(); } } ViewBag.Message = "Щось пройшло не так..."; return View(); }
public ActionResult ChangeDate(TripDate model) { if (ModelState.IsValid) { if (model.Start > model.Finish) { ModelState.AddModelError("", "Дата початку має бути раніше за дату кінця"); return View(); } if (Math.Abs(model.Start.Year - DateTime.Now.Year) > 100) { ModelState.AddModelError("", "Неправильно введена дата початку"); return View(); } if (Math.Abs(model.Finish.Year - DateTime.Now.Year) > 100) { ModelState.AddModelError("", "Неправильно введена дата кінця"); return View(); } using (var db = new RazomContext()) { Travels t = db.Travels.Find(model.ID); t.DateStart = model.Start; t.DateFinish = model.Finish; db.SaveChanges(); } return RedirectToAction("Show", new { id = model.ID }); } return View(); }
public ActionResult Show(int id) { Trip t = new Trip(); using (var db = new RazomContext()) { t.Finish = db.Travels.Find(id).DateFinish ?? DateTime.Now.AddDays(1); t.Start = db.Travels.Find(id).DateStart ?? DateTime.Now; t.Name = db.Travels.Find(id).Name; t.Places = (from tr in db.Travels join tp in db.TravelPlaces on tr.TravelID equals tp.TravelID join pl in db.Places on tp.PlaceID equals pl.PlaceID where tr.TravelID == id select pl).ToList(); t.Users = (from tr in db.Travels join h in db.History on tr.TravelID equals h.TravelID join u in db.Users on h.UserID equals u.UserID where tr.TravelID == id select u).ToList(); t.ID = id; t.Messages = (from tr in db.Message join u in db.Users on tr.UserID equals u.UserID where tr.TravelID == id select new PostedMessage { AuthorName = u.FirstName + " " + u.SecondName, ID = tr.MessageID, Text = tr.Text }).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; t.UserID = user; if (db.History.Where(h => h.UserID == user).Count() > 0) { t.isEditable = true; } else t.isEditable = false; } return View(t); }
public ActionResult ConfirmAddPlace(int id, int uid) { string name = ""; using (var db = new RazomContext()) { Places place = db.Places.Find(uid); name = place.Name; ViewBag.Name = name; ViewBag.id = id; TravelPlaces tp = new TravelPlaces(); tp.TravelID = id; tp.PlaceID = uid; db.TravelPlaces.Add(tp); db.SaveChanges(); } return View(); }
private List<AccountModel> getSearchList(string token) { List<KeyValuePair<int ,List<string>>> ids = PeopleSearchEngine.PeopleSearchEngine.GetSearchResultIndexes(token); List<AccountModel> result = new List<AccountModel>(); using (var db = new RazomContext()) { AccountModel a; foreach (var item in ids) { Users p = db.Users.Find(item.Key); int photo = db.Users.Where(ph => ph.Avatar != null).SingleOrDefault(ph => ph.UserID == p.UserID) != null ? db.Users.Where(ph => ph.Avatar != null).SingleOrDefault(ph => ph.UserID == p.UserID).UserID : 0; NetworkAccounts fs = db.NetworkAccounts.Where(ac => ac.NetworkID == 1).FirstOrDefault(ac => ac.UserID == p.UserID); NetworkAccounts tw = db.NetworkAccounts.Where(ac => ac.NetworkID == 2).FirstOrDefault(ac => ac.UserID == p.UserID); NetworkAccounts vk = db.NetworkAccounts.Where(ac => ac.NetworkID == 3).FirstOrDefault(ac => ac.UserID == p.UserID); a = new AccountModel { ID = p.UserID, FirstName = p.FirstName, SecondName = p.SecondName, EMail = p.Email, Login = p.Login, Phone = p.Phone, FoursquareAccount = fs != null ? fs.ProfileURL : "", TwitterAccount = tw != null ? tw.ProfileURL : "", VKAccount = vk != null ? vk.ProfileURL : "", Associations = item.Value }; result.Add(a); } } return result; }
public ActionResult ActicateAccount(string id) { if (id == "fs") { return Redirect("https://foursquare.com/oauth2/authenticate?client_id=YRRHVMJV1QOGLS23RLWMKN2S3NF1B13C1ROF22N5Z1UT2YYN&response_type=code&redirect_uri=http://brainiac09-001-site1.myasp.net/Account/ConfirmNetworkAccount"); } else if (id == "tw") { HttpCookie cookie = Request.Cookies[FormsAuthentication.FormsCookieName]; FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value); int userID = 0; using(var db = new RazomContext()) { userID = db.Users.Where(u => u.Login == ticket.Name).SingleOrDefault().UserID; } Thread task = new Thread(t => Twitter.WriteTwitterDataToDB(userID)); task.Start(); ViewBag.Network = id; ViewBag.UserID = userID; return View(); } else if (id == "vk") { HttpCookie cookie = Request.Cookies[FormsAuthentication.FormsCookieName]; FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value); int userID = 0; using (var db = new RazomContext()) { userID = db.Users.Where(u => u.Login == ticket.Name).SingleOrDefault().UserID; } Thread task = new Thread(t => VK.WriteUserVkDataToDB(userID)); task.Start(); ViewBag.Network = id; ViewBag.UserID = userID; return View(); } ViewBag.Network = "Така соціальна мережа не підтримуєтсья!"; return View(); }
public ActionResult ChangeDate(int id) { TripDate td = new TripDate(); using (var db = new RazomContext()) { td.ID = id; td.Start = db.Travels.Find(id).DateStart ?? DateTime.Now; td.Finish = db.Travels.Find(id).DateFinish ?? DateTime.Now.AddDays(1); } return View(td); }
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); }
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); }
public ActionResult Create(Trip trip) { if (ModelState.IsValid) { if (trip.Start > trip.Finish) { ModelState.AddModelError("", "Дата початку має бути раніше за дату кінця"); return View(); } if (Math.Abs(trip.Start.Year - DateTime.Now.Year) >100) { ModelState.AddModelError("", "Неправильно введена дата початку"); return View(); } if (Math.Abs(trip.Finish.Year - DateTime.Now.Year) > 100) { ModelState.AddModelError("", "Неправильно введена дата кінця"); return View(); } using (var db = new RazomContext()) { HttpCookie cookie = Request.Cookies[FormsAuthentication.FormsCookieName]; FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value); Users user = db.Users.Where(u => u.Login == ticket.Name).SingleOrDefault(); Travels t = new Travels { DateStart = trip.Start, DateFinish = trip.Finish, Name = trip.Name }; db.Travels.Add(t); db.SaveChanges(); db.History.Add(new History { UserID = user.UserID, TravelID = t.TravelID }); db.SaveChanges(); return RedirectToAction("Show", "Trip", new { id = t.TravelID }); } } return View(); }
public ActionResult ConfirmTrip(int id) { HttpCookie cookie = Request.Cookies[FormsAuthentication.FormsCookieName]; FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value); string username = ticket.Name; using (var db = new RazomContext()) { Users user = db.Users.Where(u => u.Login == username).FirstOrDefault(); Invite inv = db.Invite.Where(i => i.TravelID == id).FirstOrDefault(); db.Invite.Remove(inv); db.SaveChanges(); History h = new History { UserID = user.UserID, TravelID = id }; db.History.Add(h); db.SaveChanges(); } return RedirectToAction("Show", "Trip", new { id=id }); }
public ActionResult ConfirmAddUser(int id, int uid) { string name = ""; using (var db = new RazomContext()) { Users user = db.Users.Find(uid); name = user.FirstName + " " + user.SecondName; ViewBag.Name = name; ViewBag.id = id; Invite inv = new Invite(); inv.TravelID = id; inv.UserID = uid; db.Invite.Add(inv); db.SaveChanges(); } return View(); }
public ActionResult DisplayPicture(int id = -1) { if (id != -1) { using (var db = new RazomContext()) { byte[] image = db.PhotosPlace.Find(id).FileFoto; if (image == null) { return null; } else return File(image, "image/jpg"); } } return null; }
public ActionResult ChangeName(int id) { ViewBag.ID = id; using (var db = new RazomContext()) { ViewBag.Name = db.Travels.Find(id).Name; } return View(); }
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); }
public ActionResult PagerAddPlace(FormCollection form) { List<ShortPlace> places = new List<ShortPlace>(); int page = int.Parse(form["page"].ToString()); int travel_id = int.Parse(form["t_id"].ToString()); string token = form["id"].ToString(); using (var db = new RazomContext()) { PlaceSearchEngine.PlaceSearchEngine engine = new PlaceSearchEngine.PlaceSearchEngine(); List<int> placeIDs = engine.searchPlaces(token); List<int> placeInThisTrip = (from pl in db.Places join tp in db.TravelPlaces on pl.PlaceID equals tp.PlaceID join tr in db.Travels on tp.TravelID equals tr.TravelID where tr.TravelID == travel_id select pl.PlaceID).ToList(); foreach (var item in placeIDs) { if (!placeInThisTrip.Contains(item)) { places.Add(db.Places.Where(p => p.PlaceID == item).Select(p => new ShortPlace { ID = p.PlaceID, Name = p.Name }).FirstOrDefault()); } } } int pageSize = 6; int pCount = 0; if (places.Count % pageSize == 0) { pCount = places.Count / pageSize; } else pCount = places.Count / pageSize + 1; places = places.Skip((page - 1) * pageSize).Take(pageSize).ToList(); PlaceAddForm paf = new PlaceAddForm() { Token = token, TripID = travel_id, PlacesInfo = new PlaceCollection() { Places = places, CurrentPage = page, PagesCount = pCount } }; return View("AddPlace",paf); }
public ActionResult Show(int id = -1, int page = 1) { if (id != -1) { FullPlace place = new FullPlace(); using (var db = new RazomContext()) { Places p = db.Places.SingleOrDefault(i => i.PlaceID == id); place.City = db.Region.Find(p.CityID).Name; place.Name = p.Name; place.PlaceID = p.PlaceID; place.PlaceType = db.PlaceType.Find(p.PlaceTypeID) == null ? string.Empty : db.PlaceType.Find(p.PlaceTypeID).Type; place.Rating = p.Rating ?? 0; place.Address = p.Address; place.tags = (from pl in db.Places join ttp in db.TagToPlace on pl.PlaceID equals ttp.PlaceID join t in db.Tag on ttp.TagID equals t.TagID where pl.PlaceID == id select t.NameTag).ToList(); place.PhotoUrls = (from img in db.PhotosPlace where img.href != null && img.PlaceID == id select img.href).ToList(); place.PhotoBytes = (from img in db.PhotosPlace where img.FileFoto != null && img.PlaceID == id select img.FotoID).ToList(); place.Coordinates = p.Coordinates; HttpCookie cookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if (cookie != null) { FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value); string username = ticket.Name; Users user = db.Users.SingleOrDefault(u => u.Login == username); place.IsEditable = user.IsAdmin ?? false; place.IsAuthorized = true; place.IsInFavorite = db.FuturePlace.Where(fp => fp.PlaceID == id && fp.UserID == user.UserID).Count() == 0 ? false : true; } else { place.IsEditable = false; place.IsAuthorized = false; } place.Comment = db.Comments.Where(c => c.PlaceID == id).ToList(); place.Comment.Reverse(); int pageSize = 3; int pCount = 0; if (place.Comment.Count() % pageSize == 0) { pCount = place.Comment.Count() / pageSize; } else pCount = place.Comment.Count() / pageSize + 1; place.Comment = place.Comment.Skip((page-1)*pageSize).Take(pageSize).ToList(); place.CurrentPage = page; place.PagesCount = pCount; } return View(place); } return View(); }
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); }
private List<ShortPlace> getSearchList(string token) { PlaceSearchEngine.PlaceSearchEngine engine = new PlaceSearchEngine.PlaceSearchEngine(); List<int> ids = engine.searchPlaces(token); List<ShortPlace> result = new List<ShortPlace>(); using (var db = new RazomContext()) { ShortPlace sp; foreach (int item in ids) { Places p = db.Places.Find(item); if (p == null) { continue; } List<string> Tags = (from t in db.Tag join ttp in db.TagToPlace on t.TagID equals ttp.TagID where ttp.PlaceID == item select t.NameTag).ToList(); var photo = db.PhotosPlace.Where(ph => ph.FileFoto != null && ph.PlaceID == p.PlaceID).ToList(); var photoUrl = db.PhotosPlace.Where(ph => ph.href != null && ph.PlaceID == p.PlaceID).ToList(); sp = new ShortPlace { Name = p.Name, City = db.Region.Find(p.CityID).Name, PlaceID = p.PlaceID, PhotoByte = photo.Count != 0 ? photo.First().FotoID : 0, PhotoUrl = photoUrl.Count != 0 ? photoUrl.First().href : "", Rating = p.Rating ?? 0, PlaceType = p.PlaceType != null ? db.PlaceType.Find(p.PlaceTypeID).Type : string.Empty, tags = Tags }; result.Add(sp); } } return result; }
public ActionResult Recommend(int id, int uid) { List<KeyValuePair<int, List<string>>> output = Recommender.Get(uid); foreach (var item in output) { while (item.Value.Contains(string.Empty)) { item.Value.Remove(string.Empty); } } List<AccountModel> people = new List<AccountModel>(); using (var db = new RazomContext()) { output.ForEach(o => { Users u = db.Users.Find(o.Key); people.Add(new AccountModel { Associations = o.Value, EMail = u.Email, FirstName = u.FirstName, SecondName = u.SecondName, ID = u.UserID, Login = u.Login }); }); } AccountCollection ac = new AccountCollection { Accounts = people }; return View(new PeopleAddForm { TripID = id, AccountsInfo = ac }); }
public ActionResult LeftTrip(int id) { HttpCookie cookie = Request.Cookies[FormsAuthentication.FormsCookieName]; FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value); string username = ticket.Name; using (var db = new RazomContext()) { int userID = db.Users.SingleOrDefault(u => u.Login == username).UserID; History hist = db.History.Where(h => h.TravelID == id && h.UserID == userID).First(); db.History.Remove(hist); db.SaveChanges(); if (db.History.Where(h => h.TravelID == id).Count() == 0) { var conect = db.TravelPlaces.Where(t => t.TravelID == id); foreach (var item in conect) { db.TravelPlaces.Remove(item); } db.SaveChanges(); Travels tr = db.Travels.Find(id); db.Travels.Remove(tr); db.SaveChanges(); } } return View(); }
public ActionResult ChangeName(FormCollection form) { string name = form["new_name"].ToString(); if (!(String.IsNullOrEmpty(name) || String.IsNullOrWhiteSpace(name))) { using (var db = new RazomContext()) { Travels t = db.Travels.Find(int.Parse(form["id"].ToString())); t.Name = name; db.SaveChanges(); } } return RedirectToAction("Show", "Trip", new { id = form["id"].ToString() }); }