public JsonResult AddComment(int groupid, int rideid, string CommentString, int ParentRideID) { var currentUser = idb.Users.Find(User.Identity.GetUserId()); if (CommentString != string.Empty) { repository.AddRideComment(CommentString, rideid, currentUser.UserName, currentUser.Id); repository.Save(); RideModelIndex RideModel = new RideModelIndex(); RideModelHelper _RideHelper = new RideModelHelper(repository); RideModel = _RideHelper.PopulateRideModel(ParentRideID, groupid, currentUser.Id, false); int commentCount = repository.GetCommentCountForRide(rideid); Task E = new Task(() => { CultureHelper _CultureHelper = new CultureHelper(repository); TimeZoneInfo TZone = _CultureHelper.GetTimeZoneInfo(currentUser.LocationID); Ride _Ride = repository.GetRideByID(rideid); string RideDate = _Ride.RideDate.ToShortDateString(); string GroupName = _Ride.Group.name; UserHelper _UserHelp = new UserHelper(); List <Rider> _Riders = repository.GetRidersAndCommentersForRideDontIncludeCurrentUser(_Ride.id, TZone, currentUser.Id); List <string> Emails = new List <string>(); foreach (Rider item in _Riders.GroupBy(x => x.userId).Select(x => x.FirstOrDefault())) { ApplicationUser ThisUser = idb.Users.Where(u => u.Id == item.userId).FirstOrDefault(); if (ThisUser != null) { if (ThisUser.ReceiveEmails) { string email = _UserHelp.GetUserEmailViaUserId(item.userId); Emails.Add(email); } } } _UserHelp.SendUsersNewCommentRideEmail(Emails, GroupName, currentUser.UserName, CommentString, _Ride.Group.id, _Ride.RideDate); }); E.Start(); return(Json(new { success = true, message = CommentString, rideid = rideid, username = currentUser.UserName, commentcount = commentCount, parentid = ParentRideID }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, Message = "Please enter a comment." }, JsonRequestBehavior.AllowGet)); } }
public JsonResult AttendSingleRide(int RideId, string Commitment, int Groupid, int ParentRideID) { var currentUser = idb.Users.Find(User.Identity.GetUserId()); Ride _Ride = new Ride(); Group _Group = new Group(); _Ride = repository.GetRideByID(RideId); _Group = repository.GetGroupByID(Groupid); Rider _Rider = new Rider { userId = currentUser.Id, Name = currentUser.UserName, Ride = _Ride, LeaveTime = DateTime.UtcNow, PercentKeen = Commitment }; repository.AddRider(_Rider, _Group); repository.Save(); SingleRideAndRandomRideViewModel _SingleRideRandomRideViewModel = new SingleRideAndRandomRideViewModel(); RideModelHelper _RideHelper = new RideModelHelper(repository); _SingleRideRandomRideViewModel = _RideHelper.PopulateSingleRideModel(RideId, currentUser.Id); string KeenCount = repository.GetKeenCountForRide(RideId).ToString(); Task E = new Task(() => { CultureHelper _CultureHelper = new CultureHelper(repository); TimeZoneInfo TZone = _CultureHelper.GetTimeZoneInfo(currentUser.LocationID); string RideDate = _Ride.RideDate.ToShortDateString(); string GroupName = _Ride.Group.name; UserHelper _UserHelp = new UserHelper(); List <Rider> _Riders = repository.GetRidersAndCommentersForRideDontIncludeCurrentUser(_Ride.id, TZone, currentUser.Id); List <string> Emails = new List <string>(); List <string> PhoneNotifications = new List <string>(); foreach (Rider item in _Riders.GroupBy(x => x.userId).Select(x => x.FirstOrDefault())) { var ThisUser = idb.Users.Find(item.userId); if (ThisUser != null) { if (ThisUser.ReceiveEmails) { string email = _UserHelp.GetUserEmailViaUserId(item.userId); Emails.Add(email); } if (ThisUser.ReceiveMobileNotifications) { string phone = _UserHelp.GetUserEmailViaUserId(item.userId); PhoneNotifications.Add(phone); } } } foreach (string u in repository.GetFollowers(currentUser.Id)) { var ThisUser = idb.Users.Find(u); if (ThisUser != null) { if (ThisUser.ReceiveEmails) { string email = _UserHelp.GetUserEmailViaUserId(u); Emails.Add(email); } if (ThisUser.ReceiveMobileNotifications) { string phone = _UserHelp.GetUserEmailViaUserId(u); PhoneNotifications.Add(phone); } } } Emails = Emails.Distinct().ToList(); foreach (string p in PhoneNotifications) { ApplicationUser _user = idb.Users.Where(d => d.Email == p).FirstOrDefault(); sendNotification(currentUser.UserName + " Is " + Commitment + " Ride " + _Group.name, _user.UserName); } _UserHelp.SendUsersGroupAttendStatusEmail(Emails, GroupName, Commitment, currentUser.UserName, _Ride.Group.id, _Ride.RideDate); }); E.Start(); Task T = new Task(() => { CloudStorageAccount storageAccount = CloudStorageAccount.Parse( ConfigurationManager.ConnectionStrings["AzureJobsData"].ConnectionString); // Create the queue client. CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); // Retrieve a reference to a queue. CloudQueue queue = queueClient.GetQueueReference("updatehomepage"); // Create the queue if it doesn't already exist. queue.CreateIfNotExists(); // Create a message and add it to the queue. CloudQueueMessage message = new CloudQueueMessage("Hello, World"); queue.AddMessage(message); }); T.Start(); return(Json(new { success = true, message = Commitment, rideid = RideId, username = currentUser.UserName, keencount = KeenCount, leavetime = DateTime.UtcNow, parentid = ParentRideID }, JsonRequestBehavior.AllowGet)); }
public ActionResult Index(int groupid = -1, int rideid = -1, int InviteId = -1, string fromhome = "false") { var currentUser = idb.Users.Find(User.Identity.GetUserId()); if (InviteId != -1) { if (repository.PrivateBunchInviteUserEmailNotSet(InviteId)) { repository.UpdateInvitePrivateUser(currentUser.Id, currentUser.Email, InviteId); repository.Save(); } } RideModelIndex RideModel = new RideModelIndex(); Group _Group = repository.GetGroupByID(groupid); //If group is null, see if we can get the group from the rideid and if so recall action with just the groupid set. if (_Group == null) { _Group = repository.GetGroupByRideID(rideid); if (_Group != null) { rideid = -1; groupid = _Group.id; return(RedirectToAction("Index", new { groupid = _Group.id })); } } if (_Group == null) { GroupModel GroupModel = new GroupModel(); GroupModel._Groups = repository.GetGroups().ToList(); GroupModel.CurrentGroupMembership = repository.CurrentGroupsForUser(currentUser.Id); return(RedirectToAction("index", "group", GroupModel)); } //Just in case location ID has not been set, set to same as ride. if (currentUser.LocationID == null) { currentUser.LocationID = _Group.Location.id; idb.SaveChanges(); } RideModelHelper _RideHelper = new RideModelHelper(repository); var t = Request.QueryString["groupId"]; if (groupid != -1 || rideid != -1) { RideModel = _RideHelper.PopulateRideModel(rideid, groupid, currentUser.Id, true); } else { GroupModel GroupModel = new GroupModel(); GroupModel._Groups = repository.GetGroups().ToList(); GroupModel.CurrentGroupMembership = repository.CurrentGroupsForUser(currentUser.Id); return(RedirectToAction("index", "group", GroupModel)); } if (RideModel.Ride != null) { } else { GroupModel GroupModel = new GroupModel(); GroupModel._Groups = repository.GetGroups().ToList(); GroupModel.CurrentGroupMembership = repository.CurrentGroupsForUser(currentUser.Id); return(RedirectToAction("index", "group", GroupModel)); } RideModel.FromHome = fromhome; RideModel.IsFavourite = repository.IsInFavouriteList(RideModel.Group.id, currentUser.Id); if (_Group.Lat != null) { RideModel.lat = _Group.Lat; } if (_Group.Lng != null) { RideModel.lng = _Group.Lng; } if (RideModel.Group.IsPrivate) { if (!repository.IsInvitedToPrivateBunch(RideModel.Group.id, currentUser.Id)) { GroupModel GroupModel = new GroupModel(); GroupModel._Groups = repository.GetGroups().ToList(); GroupModel.CurrentGroupMembership = repository.CurrentGroupsForUser(currentUser.Id); return(RedirectToAction("index", "group", GroupModel)); } } RideModel.RouteCount = repository.RouteCountForGroup(RideModel.Group.id); return(View(RideModel)); }