コード例 #1
0
        public string CreateVisit(VisitedCreate model)
        {
            var entity = new Visited()
            {
                UserID         = _userId,
                TrailID        = model.TrailID,
                Rating         = model.Rating,
                Review         = model.Review,
                AddToFavorites = model.AddToFavorites
            };

            using (var ctx = new ApplicationDbContext())
            {
                try { var trail = ctx.Trails.Single(e => e.ID == model.TrailID); }
                catch { return("Invalid Trail ID"); }

                try { var user = ctx.Users.Single(e => e.ID == _userId); }
                catch { return("Invalid User ID"); }

                try { var visited = ctx.Visits.Single(e => e.TrailID == model.TrailID && e.UserID == _userId); }
                catch
                {
                    ctx.Visits.Add(entity);
                    ctx.SaveChanges();
                    return("Okay");
                }

                return("User Revisit");
            }
        }
コード例 #2
0
        public string CreateVisit(VisitedCreate model)
        {
            var entity = new Visited()
            {
                Profile_ID     = _userId,
                BusinessID     = model.BusinessID,
                EventID        = model.EventID,
                Rating         = model.Rating,
                Review         = model.Review,
                AddToFavorites = model.AddToFavorites,
                AddToCalendar  = model.AddToCalendar,
            };

            using (var ctx = new ApplicationDbContext())
            {
                try
                {
                    ctx.Visits.Add(entity);
                    ctx.SaveChanges();
                    return("Okay");
                }
                catch
                { }
                return("Error");
            }
        }
コード例 #3
0
        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"));
            }
        }
コード例 #4
0
        //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());
        }
コード例 #5
0
        /// <summary>
        /// Create a New Visit
        /// </summary>
        /// <returns>Returns A New Visit</returns>
        public IHttpActionResult Post(VisitedCreate visited)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var visitedService = CreateVisitService();

            result = visitedService.CreateVisit(visited);
            if (result == "Invalid Trail ID")
            {
                return(BadRequest("Invalid Trail ID."));
            }
            if (result == "Invalid User ID")
            {
                return(BadRequest("Invalid User ID."));
            }
            if (result == "User Revisit")
            {
                return(BadRequest("User has already Visited this Trail."));
            }
            return(Ok());
        }