public List <EventModel> SearchAction(string search) { System.Diagnostics.Debug.WriteLine("ID ==" + search); string[] broken_string; //will have all search terms in string array broken_string = search.Split(' '); if (broken_string == null) { return(new List <EventModel>()); } for (int i = 0; i < broken_string.Length; ++i) { broken_string[i] = broken_string[i].ToLower(); } Dictionary <int, EventModel> events = new Dictionary <int, EventModel>(); //building dictionary of events for (int i = 0; i < broken_string.Count(); i++) //all terms { if (_standardDbContext.Find <SearchTagModel>(broken_string[i]) != null) { for (int k = 0; k < _standardDbContext.Find <SearchTagModel>(broken_string[i]).event_id.Count(); k++) //cycles through the amount of event ids it has { if (!events.ContainsKey(_standardDbContext.Find <SearchTagModel>(broken_string[i]).event_id[k])) //the actual event id { int value = _standardDbContext.Find <SearchTagModel>(broken_string[i]).event_id[k]; events.Add(value, _standardDbContext.Find <EventModel>(value)); //the event id is added as well as the model } } } } return(new List <EventModel>(events.Values)); }
public IActionResult Index(int id) { if (_standardDbContext.Find <EventModel>(id) != null) { return(View(_standardDbContext.Find <EventModel>(id))); } return(Error()); }
// function for event modification by replacing the event in the database // works similarly to event creation except the event Id is preserved // this is in order to keep the url for the event page consistent, // which allows for features such as QR codes and Mapbox to function properly public IActionResult ApproveEvent(int id) { EventModel unapproved_event = _standardDbContext.Find <EventModel>(id); if (unapproved_event != null) { unapproved_event.Approved = true; } _standardDbContext.SaveChanges(); _standardDbContext.Dispose(); return(RedirectToAction("Index")); }
public IActionResult Index() { if (User.Identity.IsAuthenticated) { List <int> event_ids = _standardDbContext.Users.Find(_userManager.GetUserId(User)).AuthoredEvents; if (event_ids == null) { return(View(new List <EventModel>())); } List <EventModel> events = new List <EventModel>(); for (int i = 0; i < event_ids.Count; ++i) { if (_standardDbContext.Find <EventModel>(event_ids[i]) != null) { events.Add(_standardDbContext.Find <EventModel>(event_ids[i])); } } return(View(events)); } else { return(View(new List <EventModel>())); } }
public async Task <IActionResult> CreateEvent(string name, string description, IFormFile flyer) { if (name == null || name.Length == 0) { return(Content("Name too short")); } if (flyer == null || Path.GetExtension(flyer.FileName) == String.Empty || Path.GetExtension(flyer.FileName) == null) { return(Content("Flyer not attached, or incorrect file extension.")); } //Need check on file extension. var rand = new Random(); int id = 0; while (_standardDbContext.Find <EventModel>(id) != null || id == 0) { id = rand.Next(); } var path = String.Concat(Directory.GetCurrentDirectory(), "/wwwroot/", id.ToString(), Path.GetExtension(flyer.FileName)); using (var stream = new FileStream(path, FileMode.Create)) { await flyer.CopyToAsync(stream); } //System.Diagnostics.Debug.WriteLine("FILE LENGTH ==", Path.GetExtension(flyer.FileName) == String.Empty, "Long"); _standardDbContext.Add(new EventModel { Id = id, Name = name, Description = description, FileName = String.Concat(id.ToString(), Path.GetExtension(flyer.FileName)) }); _standardDbContext.SaveChanges(); _standardDbContext.Dispose(); return(RedirectToAction("Index")); }
public async Task <IActionResult> CreateEvent(string name, string description, IFormFile flyer, string date, string time, string building, int room, int likes, string category) { if (name == null || name.Length == 0) { return(Content("Name too short")); } if (flyer == null || Path.GetExtension(flyer.FileName) == String.Empty || Path.GetExtension(flyer.FileName) == null) { return(Content("Flyer not attached, or incorrect file extension.")); } string[] broken_string = breakString(name); for (int i = 0; i < broken_string.Length; ++i) { broken_string[i] = broken_string[i].ToLower(); } int id = new Random().Next(); while (_standardDbContext.Find <EventModel>(id) != null) { id = new Random().Next(); } List <int> list = new List <int>(id); for (int i = 0; i < broken_string.Count(); ++i) { if (_standardDbContext.Find <SearchTagModel>(broken_string[i]) == null) { _standardDbContext.Add(new SearchTagModel { tag = broken_string[i], event_id = new List <int>() }); _standardDbContext.Find <SearchTagModel>(broken_string[i]).event_id.Add(id); } else { _standardDbContext.Find <SearchTagModel>(broken_string[i]).event_id.Add(id); } } System.Diagnostics.Debug.WriteLine("TIME ==", time, "DATE ==", date, /* "CAMPUS ==", campus,*/ "BUILDING ==", building); _standardDbContext.Add(new EventModel { Id = id, Approved = false, Author = _userManager.GetUserId(User), Title = name, Description = description, FileName = String.Concat(id.ToString(), Path.GetExtension(flyer.FileName)), Date = date, Time = time, Building = building, Room = room, Latitude = _standardDbContext.Find <LocationModel>(building).Latitude, Longitude = _standardDbContext.Find <LocationModel>(building).Longitude, Likes = 0, Category = category }); _standardDbContext.Users.Find(_userManager.GetUserId(User)).AuthoredEvents.Add(id); _standardDbContext.SaveChanges(); _standardDbContext.Dispose(); await createImage(id, flyer); return(RedirectToAction("Index")); }