// for the Like functionality, increments the Likes by 1 and returns the the Event View public LocalRedirectResult Like(int id, string email) { if (email != null) { // adding a like record in the Likes table throught the standardDbContext // parameters include EventId, Time(current date/time stamp), unique LikeId and Email _standardDbContext.Add(new LikeModel { EventId = id, Time = DateTime.Now, LikeId = new Random().Next(), Email = email }); // updates the Like count in the Events table by incrementing the Likes column by 1 var count = _standardDbContext.Likes .Where(o => o.EventId == id) .Count(); _standardDbContext.Find <EventModel>(id).Likes = count + 1; } _standardDbContext.SaveChanges(); _standardDbContext.Dispose(); string idStr = id.ToString(); string s = "/" + idStr; return(LocalRedirect(s)); }
// this LocalRedirectResult method will Add to the Email Reminder table // it stores the EmailReminderId, the EventId, Date, and Email // these are all passed from the asp-action in the Event View, "Event.html" public LocalRedirectResult scheduleEmail(int id, string date, string email) { if (email != null) { // adds parameters to the Email Reminder table _standardDbContext.Add(new EmailReminderModel { EmailReminderId = new Random().Next(), EventId = id, Date = date, Email = email }); } _standardDbContext.SaveChanges(); _standardDbContext.Dispose(); string idStr = id.ToString(); string s = "/" + idStr; //return to the View return(LocalRedirect(s)); }
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")); }