public ActionResult FollowBusiness(int id) { var businessService = CreateBusinessService(); var profileService = CreateProfileService(); var friendService = CreateFriendsService(); var thisBusiness = businessService.GetByID(id); var checkFollowing = friendService.CheckForFollow(id); var activityFeedItem = new ActivityFeedCreate(); activityFeedItem.Activity = TypeOfActivity.Follow; activityFeedItem.Content = $"{thisBusiness.Name}, {thisBusiness.City}"; activityFeedItem.ObjectID = thisBusiness.ID; activityFeedItem.ObjectType = "Business"; if (checkFollowing == true) { profileService.RemoveFeedItem(activityFeedItem); friendService.StopFollowingBusiness(id); return(RedirectToAction($"Details/{id}", "Business")); } profileService.CreateFeedItem(activityFeedItem); friendService.FollowBusiness(id); return(RedirectToAction($"Details/{id}", "Business")); }
public ActionResult Create(int id, EventCreate model) { if (!ModelState.IsValid) { return(View(model)); } var eventService = CreateEventService(); var profileService = CreateProfileService(); string result = eventService.Create(model); if (result == "okay") { var newEvent = eventService.GetByBusinessIDAndStart(model.BusinessID, model.StartDayToString); var activityFeedItem = new ActivityFeedCreate(); activityFeedItem.Activity = TypeOfActivity.NewEvent; activityFeedItem.Content = $"{newEvent.title} on {model.StartMonth}/{model.StartDay}/{model.StartYear}"; activityFeedItem.BusinessID = model.BusinessID; activityFeedItem.ObjectID = newEvent.id; activityFeedItem.ObjectType = "Event"; profileService.CreateBusinessFeedItem(activityFeedItem); TempData["SaveResult"] = "Event was created."; return(RedirectToAction($"Details/{model.BusinessID}", "Business")); } ; ModelState.AddModelError("", "Event could not be created."); return(View(model)); }
public bool UpdateFeedItem(ActivityFeedCreate model) { var entity = new ActivityFeed() { UserID = _userId, BusinessID = model.BusinessID, Activity = $"{model.Activity}", ObjectID = model.ObjectID, ObjectType = model.ObjectType, Content = model.Content, Created = DateTimeOffset.Now, }; using (var ctx = new ApplicationDbContext()) { var activity = $"{model.Activity}"; try { var oldActivity = ctx.ActivityFeed.Where(e => e.ObjectID == model.ObjectID && e.Activity == activity && e.UserID == _userId).First(); ctx.ActivityFeed.Remove(oldActivity); } catch { } ctx.ActivityFeed.Add(entity); ctx.SaveChanges(); return(true); } }
public bool RemoveFeedItem(ActivityFeedCreate model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.ActivityFeed.Single(e => e.UserID == _userId && e.Content == model.Content); ctx.ActivityFeed.Remove(entity); ctx.SaveChanges(); return(true); } }
public ActionResult DeleteEvent(int id) { var eventService = CreateEventService(); var profileService = CreateProfileService(); var deleteFeedItem = new ActivityFeedCreate(); var deletedEvent = eventService.GetByID(id); deleteFeedItem.ObjectType = "Event"; deleteFeedItem.ObjectID = deletedEvent.id; eventService.Delete(id); profileService.RemoveBusinessFeedItem(deleteFeedItem); TempData["SaveResult"] = "Event was deleted"; return(RedirectToAction($"Details/{deletedEvent.BusinessID}", "Business")); }
public bool RemoveBusinessFeedItem(ActivityFeedCreate model) { using (var ctx = new ApplicationDbContext()) { var eventFeedItems = ctx.ActivityFeed.Where(e => e.ObjectType == model.ObjectType && e.ObjectID == model.ObjectID).ToList(); var visitedItems = ctx.Visits.Where(e => e.EventID == model.ObjectID).ToList(); foreach (var events in eventFeedItems) { ctx.ActivityFeed.Remove(events); } foreach (var visits in visitedItems) { ctx.Visits.Remove(visits); } ctx.SaveChanges(); return(true); } }
public ActionResult AddToProfileCalendar(int id) { var eventService = CreateEventService(); var visitedService = CreateVisitedService(); var profileService = CreateProfileService(); var thisEvent = eventService.GetByID(id); var foundVisit = visitedService.GetVisitByEventID(id); var activityFeedItem = new ActivityFeedCreate(); activityFeedItem.Activity = TypeOfActivity.AddToCalendar; activityFeedItem.Content = $"{thisEvent.title}"; activityFeedItem.ObjectID = thisEvent.id; activityFeedItem.ObjectType = "Event"; if (foundVisit.EventID != null) { if (foundVisit.AddToCalendar == true) { foundVisit.AddToCalendar = false; profileService.RemoveFeedItem(activityFeedItem); visitedService.UpdateEventVisit(foundVisit, id); return(RedirectToAction($"Details/{foundVisit.EventID}", "Event")); } foundVisit.AddToCalendar = true; profileService.CreateFeedItem(activityFeedItem); visitedService.UpdateEventVisit(foundVisit, id); return(RedirectToAction($"Details/{foundVisit.EventID}", "Event")); } else { var model = new VisitedCreate(); model.AddToCalendar = true; model.EventID = id; profileService.CreateFeedItem(activityFeedItem); visitedService.CreateVisit(model); return(RedirectToAction($"Details/{id}", "Event")); } }
//public ActionResult AddRating(int id) //{ // var businessService = CreateBusinessService(); // var visitedService = CreateVisitedService(); // var foundVisit = visitedService.GetVisitByBusinessID(id); // ModelState.Clear(); // if (foundVisit.BusinessID == null) // { // var newVisit = new VisitedCreate(); // newVisit.BusinessID = id; // visitedService.CreateVisit(newVisit); // var model = new VisitedDetail(); // model.BusinessID = id; // return View(model); // } // return View(foundVisit); //} public ActionResult AddRating(int id, int rating) { var businessService = CreateBusinessService(); var visitedService = CreateVisitedService(); var profileService = CreateProfileService(); var business = businessService.GetByID(id); var foundVisit = visitedService.GetVisitByBusinessID(id); foundVisit.Rating = rating; var newFeedItem = new ActivityFeedCreate(); newFeedItem.Activity = TypeOfActivity.Rating; newFeedItem.ObjectType = "Business"; newFeedItem.ObjectID = id; newFeedItem.Content = $"{rating}-star rating for {business.Name}"; ModelState.Clear(); if (foundVisit.BusinessID == null) { var newVisit = new VisitedCreate(); newVisit.BusinessID = id; newVisit.Rating = rating; visitedService.CreateVisit(newVisit); profileService.CreateFeedItem(newFeedItem); return(RedirectToAction($"Details/{id}")); } string result = visitedService.UpdateRating(foundVisit, id); if (result == "Okay") { TempData["SaveResult"] = "Rating updated!"; profileService.UpdateFeedItem(newFeedItem); return(RedirectToAction($"Details/{id}")); } else { ModelState.AddModelError("", "Business could not be updated."); } return(View()); }
public bool CreateBusinessFeedItem(ActivityFeedCreate model) { var entity = new ActivityFeed() { BusinessID = model.BusinessID, Activity = $"{model.Activity}", ObjectID = model.ObjectID, ObjectType = model.ObjectType, Content = model.Content, Created = DateTimeOffset.Now, }; using (var ctx = new ApplicationDbContext()) { ctx.ActivityFeed.Add(entity); ctx.SaveChanges(); return(true); } }