Beispiel #1
0
        public ActionResult Create(ViewState viewState)
        {
            if (ModelState.IsValid)
            {
                State         newState  = new State();
                List <Series> newSeries = new List <Series>();
                int           i         = 0;

                newState.Name = viewState.Name;

                foreach (var item in viewState.PostedSeries)
                {
                    Int32.TryParse(item, out i);

                    newSeries.Add(_db.Series.Find(i));
                }

                newState.Serieses = newSeries;


                _db.States.Add(newState);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(viewState));
        }
        public ActionResult Create(Series series)
        {
            if (ModelState.IsValid)
            {
                _db.Series.Add(series);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(series));
        }
        public ActionResult StateSelect(FormCollection selectedState)
        {
            int userID = 0;

            string selected = selectedState["Id"];
            int    i        = 0;

            Int32.TryParse(selected, out i);

            if (User.Identity.IsAuthenticated)
            {
                userID = (int)Membership.GetUser(User.Identity.Name).ProviderUserKey;
            }

            UserProfile currentUser = _db.UserProfiles.Find(userID);

            currentUser.state = i;

            _db.Entry(currentUser).State = EntityState.Modified;
            _db.SaveChanges();

            return(RedirectToAction("Index", "FloorPlan"));
        }
        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 (var db = new OdeToHomesDb())
                {
                    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));
        }