示例#1
0
        public AthleteProfile Get()
        {
            AthleteProfile athlete = new AthleteProfile("11112", "brad_head", "https://graph.facebook.com/689357002/picture", "meters");

            athlete.firstName = "Brad";
            athlete.lastName  = "H";
            return(athlete);
        }
示例#2
0
        //GET BY ID CALL
        public AthleteProfile GetById(int id)
        {
            AthleteProfile user = new AthleteProfile();

            DataProvider.ExecuteCmd("dbo.Athletes_AthleteProfile_SelectById",
                                    inputParamMapper: (SqlParameterCollection paramCollection) =>
            {     // must be in the same order as our table
                paramCollection.AddWithValue("@id", id);
            },
                                    singleRecordMapper : delegate(IDataReader reader, short set)
            {
                user = Tools.DataMapper <AthleteProfile> .Instance.MapToObject(reader);
            });
            return(user);
        }
示例#3
0
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                string email    = model.Email;
                var    userName = email.Substring(0, email.IndexOf('@'));

                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };                                                                 // initialize the new Application User entity

                var result = await _userManager.CreateAsync(user, model.Password); // confirm new Application User was created successfully

                if (result.Succeeded)                                              // create the necessary athlete/ coach profile, stats, and assign the User to its Role
                {
                    var roleModel = _roleManager.Roles.SingleOrDefault(r => r.Id == model.RoleId);
                    switch (roleModel.Name)
                    {
                    case "Athlete":
                        var athleteProfile = new AthleteProfile {
                            UserId = user.Id
                        };                                                                // initialize a new Athlete Profile entity
                        var athleteStats = new AthleteStats {
                            UserId = user.Id, DateOFEntry = DateTime.Now
                        };                                                                                        // initialize a new Athlete Stats entity and add to Athlete role
                        _context.AthleteProfiles.Add(athleteProfile);
                        _context.AthleteStats.Add(athleteStats);
                        await _userManager.AddToRoleAsync(user, roleModel.Name);

                        break;

                    case "Coach":
                        var coachProfile = new CoachProfile {
                            UserId = user.Id
                        };                                                            // initialize a new Coach Profile entity and add to Coach role
                        _context.CoachProfiles.Add(coachProfile);
                        await _userManager.AddToRoleAsync(user, roleModel.Name);

                        break;

                    default:
                        break;
                    }

                    await _userManager.SetUserNameAsync(user, userName);    // set the Username within the User.Identity

                    await _userManager.UpdateAsync(user);

                    _context.SaveChanges();

                    _logger.LogInformation("User created a new account with password.");
                    _logger.LogInformation("Profile created");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);

                    await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl);

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    _logger.LogInformation("User created a new account with password.");
                    return(RedirectToLocal(returnUrl));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#4
0
 public static string AthleteFullName(AthleteProfile athlete)
 {
     return(athlete.FirstName + " " + athlete.Surname);
 }