public GameHostWebModel Get(int id) { Athlete me = null; if (this.User.Identity.IsAuthenticated) me = new UserProfileLogic(db).GetAthleteForUserName(this.User.Identity.Name); return new GameHostsLogic(db).Get(id, me != null ? me.AthleteID : 0); }
public async Task<int> NewGameHostInvite(NewGameHostInviteWebModel model) { int gameHostID = model.GameHostID; int athleteID = model.AthleteID; var me = new UserProfileLogic(db).GetAthleteForUserName(this.User.Identity.Name); var athlete = db.Athletes.Single(i => i.AthleteID == athleteID); if (athlete == null || me.AthleteID == athleteID) throw new Exception("athleteID is invalid"); GameHost gameHost = db.GameHosts.Include("Venue").Single(i => i.GameHostID == gameHostID); if (gameHost.GameHostInvites.Where(i => i.AthleteID == athleteID).Count() > 0) throw new Exception("an invite for this athlete already exists"); GameHostInvite invite = new GameHostInvite() { AthleteID = athleteID, GameHost = gameHost, IsApprovedByHost = true, TimeCreated = DateTime.UtcNow }; db.GameHostInvites.Add(invite); db.SaveChanges(); await sendAnInvite(me, athlete, gameHost, gameHost.Venue, ""); return invite.GameHostInviteID; }
public override async Task TokenEndpointResponse(OAuthTokenEndpointResponseContext context) { try { var db = new ApplicationDbContext(); string userName = context.Identity.GetUserName(); var athlete = new UserProfileLogic(db).GetAthleteForUserName(userName); if (athlete == null) { throw new Exception("athlete record doesn't exist!"); } // if this is a facebook account => make sure that the client provided a valid facebookToken if (athlete.HasFacebookId) { string facebookToken = context.TokenEndpointRequest.Parameters.Get("facebookToken"); var facebookProfileInfo = await FacebookAuthHelper.Validate(facebookToken); if (facebookProfileInfo == null) { throw new Exception("couldn't validate facebook token!"); } } } catch (Exception) { throw new Exception("Additional Byb validation failed"); } await base.TokenEndpointResponse(context); }
public async Task <int> MakeComment(NewCommentWebModel model) { int myAthleteID = new UserProfileLogic(db).GetAthleteIDForUserName(User.Identity.Name); int id = await new FeedLogic(db).MakeComment(myAthleteID, model.ObjectType, model.ObjectID, model.Text, true); return(id); }
public async Task <bool> Send(int athleteID, string messageText, bool shareMyEmail) { var me = new UserProfileLogic(db).GetAthleteForUserName(this.User.Identity.Name); var athlete = db.Athletes.Single(i => i.AthleteID == athleteID); if (messageText == null) { messageText = ""; } string linkToAthlete = new DeepLinkHelper().BuildLinkToAthlete(me.AthleteID); string linkToOpenByb = new DeepLinkHelper().BuildOpenBybLink_Athlete(me.AthleteID); // send an email string myName = me.NameOrUserName; string myEmail = me.UserName; if (string.IsNullOrEmpty(me.RealEmail) == false) { myEmail = me.RealEmail; } string html = string.Format(htmlMessage, myName, messageText, shareMyEmail ? myEmail : "notshared", linkToAthlete, linkToOpenByb); await new EmailService().SendEmailToAthlete(athlete, "Snooker Byb Message", html); // send a push notification new PushNotificationsLogic(db).SendNotification(athleteID, PushNotificationMessage.BuildPrivateMessage(me, messageText)); PushNotificationProcessor.TheProcessor.PushAllPendingNotifications(); return(true); }
public bool AddResultNotYetAcceptedByAthlete(ResultWebModel _result) { int myAthleteID = new UserProfileLogic(db).GetAthleteIDForUserName(User.Identity.Name); try { Result result = _result.ToResult(); if (result.VenueID == 0) { result.VenueID = null; } result.IsNotAcceptedByAthleteYet = true; if (result.OpponentAthleteID != myAthleteID) { throw new Exception("OpponentAthleteID must be you"); } if (result.AthleteID == myAthleteID) { throw new Exception("AthleteID cannot be you"); } db.Results.Add(result); db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public UserProfile(UserProfileModel model) { InitializeComponent(); _logic = UserProfileLogic.INSTANCE; _model = model; this.DataContext = _model; }
private void completeRegistration(string userName, string name, string facebookId) { string nameInFacebook = null; if (string.IsNullOrEmpty(facebookId) == false) { nameInFacebook = name; } var db = new ApplicationDbContext(); var athlete = new UserProfileLogic(db).CreateAthleteForUserName(userName, facebookId, nameInFacebook); new UserProfileLogic(db).UpdateAthleteProfile(athlete.AthleteID, name, GenderEnum.Unknown); // if there are any records in the session : save them to the database //var allResultTypes = db.ResultTypes.ToList(); //foreach (var resultType in allResultTypes) //{ // string tempTime = (string)this.Session[resultType.ShortName]; // if (string.IsNullOrEmpty(tempTime) == false) // { // double tempTimeInSeconds = new TimeHelper().Parse(tempTime); // Result result = new Result() // { // Athlete = athlete, // Distance = resultType.Distance.Value, // Time = tempTimeInSeconds, // Date = null, // ResultTypeID = resultType.ResultTypeID, // }; // db.Results.Add(result); // db.SaveChanges(); // } //} }
public async Task <string> UploadPicture() { var logic = new UserProfileLogic(db); var athlete = logic.GetAthleteForUserName(User.Identity.Name); var file = await Request.Content.ReadAsStreamAsync(); if (file.Length < 100) { throw new Exception("file.Length=" + file.Length.ToString()); } if (file.Length > 1000000 * 100) { throw new Exception("file.Length=" + file.Length.ToString()); } string cloudinaryAccount = System.Web.Configuration.WebConfigurationManager.AppSettings["CloudinaryAccount"]; string cloudinaryKey = System.Web.Configuration.WebConfigurationManager.AppSettings["CloudinaryKey"]; string cloudinarySecret = System.Web.Configuration.WebConfigurationManager.AppSettings["CloudinarySecret"]; var cloudinary = new CloudinaryDotNet.Cloudinary(new CloudinaryDotNet.Account(cloudinaryAccount, cloudinaryKey, cloudinarySecret)); var uploadResult = await cloudinary.UploadAsync(new CloudinaryDotNet.Actions.ImageUploadParams() { File = new CloudinaryDotNet.Actions.FileDescription("athlete" + athlete.AthleteID, file), Transformation = new Transformation().Width(500).Height(500).Crop("limit") // limit image size to 500x500 max }); //string pictureUrl = uploadResult.Uri.ToString(); string pictureUrl = "http://res.cloudinary.com/bestmybest/image/upload/" + uploadResult.PublicId + "." + uploadResult.Format; new UserProfileLogic(db).UpdateAthletePicture(athlete.AthleteID, pictureUrl); return(pictureUrl); }
public async Task <ActionResult> ResetPassword(ResetPasswordViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var user = await UserManager.FindByNameAsync(model.Email); if (user == null) { // Don't reveal that the user does not exist return(RedirectToAction("ResetPasswordConfirmation", "Account")); } var result = await UserManager.ResetPasswordAsync(user.Id, model.Code, model.Password); if (result.Succeeded) { if (new AccessPinHelper().Validate(model.Password)) { // use this as a PIN, too var logic = new UserProfileLogic(new ApplicationDbContext()); int athleteID = logic.GetAthleteIDForUserName(user.UserName); logic.SetPin(athleteID, model.Password); } return(RedirectToAction("ResetPasswordConfirmation", "Account")); } AddErrors(result); return(View()); }
public int SetLike(SetLikeWebModel model) { int myAthleteID = new UserProfileLogic(db).GetAthleteIDForUserName(User.Identity.Name); new FeedLogic(db).SetLike(myAthleteID, model.ObjectType, model.ObjectID, model.Like); return(1); }
public bool VerifyPin(VerifyPinWebModel model) { var db = new ApplicationDbContext(); bool verified = new UserProfileLogic(db).VerifyPin(model.AthleteID, model.Pin); return(verified); }
public bool RegisterDeviceToken(RegisterDeviceTokenWebModel model) { int myAthleteID = new UserProfileLogic(db).GetAthleteIDForUserName(User.Identity.Name); new PushNotificationsLogic(db).RegisterDeviceToken(myAthleteID, model.Token, model.IsApple, model.IsAndroid, !model.IsNotProduction); return(true); }
public async Task<int> NewGameHost2(NewGameHostWebModel2 model) { var me = new UserProfileLogic(db).GetAthleteForUserName(this.User.Identity.Name); var venue = db.Venues.SingleOrDefault(i => i.VenueID == model.VenueID); List<Athlete> playersToInvite = new List<Athlete>(); if (model.Invitees != null) { var ids = model.Invitees.Distinct().ToList(); if (ids.Count > 100) throw new ApplicationException("Too many athletes are being invited."); foreach (var id in ids) playersToInvite.Add(db.Athletes.Single(i => i.AthleteID == id)); } if ((model.When - DateTime.UtcNow).TotalHours < -1) throw new Exception("when is in the past"); // create the gamehost GameHost gameHost = new GameHost() { AthleteID = me.AthleteID, TimeCreated = DateTime.UtcNow, VenueID = model.VenueID, Visibility = 0,//model.Visibility, When = model.When, When_InLocalTimeZone = model.When_InLocalTimeZone, LimitOnNumberOfPlayers = model.LimitOnNumberOfPlayers, EventType = (int)model.EventType, }; db.GameHosts.Add(gameHost); // create the invites foreach (var athlete in playersToInvite) { GameHostInvite invite = new GameHostInvite() { AthleteID = athlete.AthleteID, GameHost = gameHost, IsApprovedByHost = true, TimeCreated = DateTime.UtcNow }; db.GameHostInvites.Add(invite); } db.SaveChanges(); // add the comment if (string.IsNullOrEmpty(model.Comments) == false) { await new FeedLogic(db).MakeComment(me.AthleteID, NewsfeedItemTypeEnum.GameHost, gameHost.GameHostID, model.Comments, false); } // send the invites foreach (var athlete in playersToInvite) { await sendAnInvite(me, athlete, gameHost, venue, model.Comments); } return gameHost.GameHostID; }
public List <PersonBasicWebModel> Find(string nameQuery, string country, int?metroID, bool friendsOnly = false, bool includeMyself = false) { Country countryObj = null; if (string.IsNullOrEmpty(country) == false) { countryObj = Country.Get(country); if (countryObj == null) { throw new Exception("Unknown country"); } } if (metroID == 0) { metroID = null; } int myAthleteID = 0; if (User.Identity.IsAuthenticated == true) { myAthleteID = new UserProfileLogic(db).GetAthleteIDForUserName(User.Identity.Name); } return(new PeopleLogic(db).Find(myAthleteID, nameQuery, friendsOnly, countryObj, metroID, includeMyself)); }
public bool WithdrawFriendRequest(int friendshipID) { var me = new UserProfileLogic(db).GetAthleteForUserName(this.User.Identity.Name); new FriendshipLogic(db).WithdrawFriendRequest(friendshipID, me.AthleteID); return(true); }
public bool Unfriend(int athleteID) { var me = new UserProfileLogic(db).GetAthleteForUserName(this.User.Identity.Name); new FriendshipLogic(db).Unfriend(me.AthleteID, athleteID); return(true); }
public bool AcceptFriendRequest2(int athleteID) { var me = new UserProfileLogic(db).GetAthleteForUserName(this.User.Identity.Name); new FriendshipLogic(db).AcceptFriendRequest2(athleteID, me.AthleteID); return(true); }
public RegistrationControllerLogic() { _userProfileLogic = new UserProfileLogic(); _saltLogic = new SaltLogic(); _partialAccountSaltLogic = new PartialAccountSaltLogic(); _accountLogic = new AccountLogic(); _partialAccountLogic = new PartialAccountLogic(); _securityQuestionLogic = new SecurityQuestionLogic(); }
/// <summary> /// ユーザーのプロフィールページに遷移します /// 184の場合は処理を中断します。 /// </summary> /// <param name="logic"></param> /// <param name="userId"></param> public static void GoToUserProfile(this UserProfileLogic me, string userId) { if (userId.IsNotNumber()) { return; } ProcessSupport.GoToWebBrowser(ApiURL.GO_TO_USER_PROFILE(int.Parse(userId)), Message.FAIL_GO_TO_USER_PROFILE); }
public Athlete Get() { var athlete = new UserProfileLogic(db).GetAthleteForUserName(User.Identity.Name); Athlete sanitized = new Athlete(); athlete.CopyTo(sanitized, true); return(sanitized); }
public AccountController() { _accountControllerLogic = new AccountControllerLogic(); _accountLogic = new AccountLogic(); _jAccessTokenLogic = new JAccessTokenLogic(); _saltLogic = new SaltLogic(); _userProfileLogic = new UserProfileLogic(); _zipLocationLogic = new ZipLocationLogic(); }
public NewsfeedItemWebModel SingleFromCommentID(int commentID) { int myAthleteID = new UserProfileLogic(db).GetAthleteIDForUserName(User.Identity.Name); var comment = db.Comments.Where(i => i.CommentID == commentID).Single(); int objectID = new FeedLogic(db).GetObjectIDFromComment(comment); return(new FeedLogic(db).GetNewsfeedItem(myAthleteID, (NewsfeedItemTypeEnum)comment.ObjectType, objectID)); }
public ActionResult Edit(int id) { EditUserProfile editUserProfile = new UserProfileLogic().GetEditUserProfileById(id); if (editUserProfile != null) { return(View(editUserProfile)); } return(View()); }
public List<GameHostWebModel> Find(bool friendsOnly, double? latitude = null, double? longitude = null) { var me = new UserProfileLogic(db).GetAthleteForUserName(this.User.Identity.Name); Location location = null; if (latitude != null && longitude != null) location = new Location(latitude.Value, longitude.Value); Distance distance = Distance.FromMiles(30); return new GameHostsLogic(db).FindGameHosts(me.AthleteID, location, distance, friendsOnly, DateTime.UtcNow, DateTime.UtcNow.AddDays(1000)); }
public RegistrationControllerLogic(AccountLogic accountLogic, PartialAccountLogic partialAccountLogic, PartialAccountSaltLogic partialAccountSaltLogic, SaltLogic saltLogic, UserProfileLogic userProfileLogic, SecurityQuestionLogic securityQuestionLogic) { _accountLogic = accountLogic; _partialAccountLogic = partialAccountLogic; _partialAccountSaltLogic = partialAccountSaltLogic; _saltLogic = saltLogic; _userProfileLogic = userProfileLogic; _securityQuestionLogic = securityQuestionLogic; }
public List <PersonBasicWebModel> PlayedAtVenue(int venueID) { int myAthleteID = 0; if (User.Identity.IsAuthenticated == true) { myAthleteID = new UserProfileLogic(db).GetAthleteIDForUserName(User.Identity.Name); } return(new PeopleLogic(db).GetPlayedAtVenue(myAthleteID, venueID)); }
public PersonFullWebModel Get(int athleteID) { int myAthleteID = 0; if (User.Identity.IsAuthenticated == true) { myAthleteID = new UserProfileLogic(db).GetAthleteIDForUserName(User.Identity.Name); } return(new PeopleLogic(db).GetFull(myAthleteID, athleteID)); }
public List <PersonBasicWebModel> Friends(int athleteID) { int myAthleteID = 0; if (User.Identity.IsAuthenticated == true) { myAthleteID = new UserProfileLogic(db).GetAthleteIDForUserName(User.Identity.Name); } return(new PeopleLogic(db).GetFriends(myAthleteID, athleteID)); }
public NewsfeedWebModel Metro(int id) { int myAthleteID = 0; if (User.Identity.IsAuthenticated) { myAthleteID = new UserProfileLogic(db).GetAthleteIDForUserName(User.Identity.Name); } var newsfeed = new FeedLogic(db).GetNewsfeedForMetro(myAthleteID, id); return(newsfeed); }