Example #1
0
        public async Task<ActionResult> Create([Bind(Include = "FirstName,LastName,EmailAddress,BirthDate,Gender,SubscriptionLength,SubscriptionId")] AthleteViewModel model)
        {
            Athlete athlete = new Athlete
            {
                FirstName = model.FirstName,
                LastName = model.LastName,
                EmailAddress = model.EmailAddress,
                Gender = model.Gender,
                BirthDate = model.BirthDate,
                Subscription = _db.Subscriptions.Single(x => x.Id.Equals(model.SubscriptionId)),
                SubscriptionLength = model.SubscriptionLength,
            };

            athlete.Reminders = new ClassReminders
            {
                Athlete = athlete,
                AthleteId = athlete.Id,
                Reminders = new List<Class>()
            };

            if (athlete.EmailAddress == "*****@*****.**")
            {
                List<Class> pastClasses = _db.Classes.Where(c => c.Time <= DateTime.Now).ToList();
                athlete.Classes = pastClasses;
            }

            if (ModelState.IsValid)
            {
                _db.Athletes.Add(athlete);
                await _db.SaveChangesAsync();
                await BeginAthleteSetup(athlete);
                return RedirectToAction("Index");
            }

            return View(athlete);
        }
Example #2
0
        public async Task BeginAthleteSetup(Athlete athlete)
        {
            Guid token = Guid.NewGuid();
            string emailBody = Utilities.Constants.GetEmailBody(athlete.FirstName, "CrossFit Example", token);
            await _emailSender.SendEmailAsync(athlete.EmailAddress, "Welcome to CrossFit Example!", emailBody);

            var keys = new AthleteSignupKey
            {
                Token = token.ToString(),
                Athlete = athlete
            };

            _db.AthleteSignupKeys.Add(keys);
            await _db.SaveChangesAsync();
        }