public ActionResult Create(Athlete athlete)
        {
            if (ModelState.IsValid)
            {
                db.Athletes.Add(athlete);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(athlete));
        }
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider       = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (DecathlonContext db = new DecathlonContext())
                {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.UserProfiles.Add(new UserProfile {
                            UserName = model.UserName
                        });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return(RedirectToLocal(returnUrl));
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl           = returnUrl;
            return(View(model));
        }
Beispiel #3
0
        public ActionResult SaveResult(int eventId, int athleteId, double?result)
        {
            var athlete = db.Athletes.Find(athleteId);

            if (athlete != null)
            {
                var log = new Log();
                log.AthleteName = athlete.Name;
                log.Event       = GetName(eventId);
                log.Result      = result;
                log.LogTime     = DateTime.Now;
                switch ((EventEnum)eventId)
                {
                case EventEnum.Meter100:
                    athlete.Meter100 = result;
                    break;

                case EventEnum.Meter1500:
                    athlete.Meter1500 = result;
                    break;

                case EventEnum.Meter400:
                    athlete.Meter400 = result;
                    break;

                case EventEnum.Hurdles110:
                    athlete.Hurdles110 = result;
                    break;

                case EventEnum.LongJump:
                    athlete.LongJump = result;
                    break;

                case EventEnum.ShotPut:
                    athlete.ShotPut = result;
                    break;

                case EventEnum.HighJump:
                    athlete.HighJump = result;
                    break;

                case EventEnum.DiscusThrow:
                    athlete.DiscusThrow = result;
                    break;

                case EventEnum.PoleVault:
                    athlete.PoleVault = result;
                    break;

                case EventEnum.JavelinThrow:
                    athlete.JavelinThrow = result;
                    break;

                default:
                    return(Content("Could not find event"));
                }
                db.Logs.Add(log);
                db.SaveChanges();
                return(Content("Saved"));
            }
            return(Content("Could not find Athlete"));
        }