Ejemplo n.º 1
0
        public ActionResult DisplayUsers()
        {
            DisplayUsersViewModel main = new DisplayUsersViewModel();

            try
            {
                var    UserId        = System.Web.HttpContext.Current.User.Identity.GetUserId();
                double userLatitude  = (from x in db.Checkin where x.UserId == UserId && x.Active == true select x.Latitude).First();
                double userLongitude = (from x in db.Checkin where x.UserId == UserId && x.Active == true select x.Longitude).First();
                int    users100ft    = 0;
                int    users300ft    = 0;
                int    users1000ft   = 0;
                int    usersHalf     = 0;
                int    usersMile     = 0;
                int    users5Mile    = 0;

                foreach (var activeUser in db.Checkin.Where(n => n.Active == true).Where(n => n.UserId != UserId))
                {
                    double userDistance = DistanceFinder.FindActivitiesDistance(userLatitude, userLongitude, activeUser.Latitude, activeUser.Longitude);

                    if (userDistance < .00036)
                    {
                        users100ft += 1;
                    }
                    if (userDistance < .00109)
                    {
                        users300ft += 1;
                    }
                    if (userDistance < .00363)
                    {
                        users1000ft += 1;
                    }
                    if (userDistance < .00958)
                    {
                        usersHalf += 1;
                    }
                    if (userDistance < .01916)
                    {
                        usersMile += 1;
                    }
                    if (userDistance < .09581)
                    {
                        users5Mile += 1;
                    }
                }
                string usersDistance = DistanceFinder.ConstructUsersDistance(users100ft, users300ft, users1000ft, usersHalf, usersMile, users5Mile);
                main.Users_Distance = usersDistance;
            }
            catch { main.Users_Distance = null; }
            return(PartialView(main));
        }
Ejemplo n.º 2
0
        public ActionResult ViewActivities(UserToActivityModel model)
        {
            //inactivate checkins over an hour old
            foreach (var row in db.Checkin.Where(n => n.Active == true))
            {
                if (DateTime.Now >= row.CheckinTime.AddHours(1))
                {
                    row.Active = false;
                }
            }
            //inactivate activities past their expiration times
            foreach (var row in db.Activity.Where(n => n.Active == true))
            {
                if (DateTime.Now >= row.TimeEnd)
                {
                    row.Active = false;
                }
            }
            db.SaveChanges();
            var UserId = System.Web.HttpContext.Current.User.Identity.GetUserId();

            MainPageViewModel main = new MainPageViewModel();

            main.Messages       = new List <string>();
            main.ActivityJoined = model.Id;
            main.UserId         = UserId;
            // find out if user is checked in
            foreach (var checkin in db.Checkin.Where(n => n.Active))
            {
                if (checkin.UserId == UserId)
                {
                    main.CheckedIn = true;
                    break;
                }
                else
                {
                    main.CheckedIn = false;
                }
            }
            // create available activities
            main.Activities_Invitees = new List <Activity_InviteesViewModel>();
            main.UserToActivity      = new List <UserToActivityModel>();
            foreach (var row in db.UserToActivity.Where(n => n.UserId == UserId))
            {
                main.UserToActivity.Add(row);
            }
            ActivitiesViewModel activities = new ActivitiesViewModel();

            activities.Activities = new List <ActivityModel>();
            foreach (var activity in db.Activity.Where(n => n.Active == true))
            {
                activities.Activities.Add(activity);
            }
            try
            {
                double userLatitude  = (from x in db.Checkin where x.UserId == UserId && x.Active == true select x.Latitude).First();
                double userLongitude = (from x in db.Checkin where x.UserId == UserId && x.Active == true select x.Longitude).First();
                foreach (var activity in activities.Activities)
                {
                    //find activites within creator's specified area
                    double activityDistance = DistanceFinder.FindActivitiesDistance(userLatitude, userLongitude, activity.Latitude, activity.Longitude);
                    if (activityDistance <= activity.Area)
                    {
                        Activity_InviteesViewModel activity_Invitees = new Activity_InviteesViewModel();
                        activity_Invitees.Activity  = activity;
                        activity_Invitees.Distance  = DistanceFinder.ConvertActivityDistance(activityDistance);
                        activity_Invitees.timeStart = activity_Invitees.Activity.TimeStart.ToShortTimeString();
                        activity_Invitees.timeEnd   = activity_Invitees.Activity.TimeEnd.ToShortTimeString();
                        //find users that joined that same activity.
                        List <string> invitees = new List <string>();

                        foreach (var invitee in db.UserToActivity.Include(n => n.User))
                        {
                            if (invitee.ActivityId == activity.Id && invitee.UserId != null)
                            {
                                //Ratings
                                Joiner joiner      = new Joiner(invitee.User.FirstName, invitee.User.Rating, invitee.User.RatingCount, invitee.Message);
                                string listInvitee = joiner.CreateRatingString();
                                invitees.Add(listInvitee);

                                //Messages
                                if (invitee.Message != null)
                                {
                                    string message = joiner.CreateMessageString();
                                    main.Messages.Add(message);
                                }
                            }
                        }

                        activity_Invitees.Invitees = new SelectList(invitees);

                        main.Activities_Invitees.Add(activity_Invitees);
                        ViewData["Joined"] = new SelectList(invitees);
                        foreach (var row in main.UserToActivity)
                        {
                            if (row.ActivityId == activity.Id)
                            {
                                main.ActivityJoined = row.ActivityId;
                            }
                        }
                    }
                }
            }
            catch { }
            return(View(main));
        }