public ActionResult Create(RegisterModel user)
        {
            if (ModelState.IsValid)
            {

                try
                {

                    WebSecurity.CreateUserAndAccount(user.UserName, user.Password);
                    Roles.AddUserToRole(user.UserName, user.Role);
                    UserProfile userProfile;
                    using (var db =new  MultikinoDb())
                    {
                        var lista = db.UserProfiles.Where(n => n.UserName == user.UserName).ToList();
                        int id  = lista[0].UserId;
                        userProfile = db.UserProfiles.Find(id);
                        userProfile.Role = user.Role;
                        db.Entry(userProfile).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    return RedirectToAction("Index");
                }
                catch (MembershipCreateUserException e)
                {
                }
            }
            return RedirectToAction("Index");
        }
 public ActionResult Miejsce(int id = 0,int id2=0)
 {
     using (var db = new MultikinoDb())
     {
         Bilet bilet = new Bilet();
         bilet.IdMiejsca = id;
         bilet.IdSeansu = id2;
         string UserName = User.Identity.Name;
         var lista = db.UserProfiles.Where(u => u.UserName == UserName).ToList();
         bilet.IdUsera = lista.Last().UserId;
         db.Bilety.Add(bilet);
         db.SaveChanges();
     }
     return RedirectToAction("Index");
 }
 public ActionResult Delete(int id)
 {
     using (var db = new MultikinoDb())
     {
         UserProfile user = db.UserProfiles.Find(id);
         try
         {
             Roles.RemoveUserFromRole(user.UserName, user.Role);
             ((SimpleMembershipProvider)Membership.Provider).DeleteAccount(user.UserName);
             db.UserProfiles.Remove(user);
             db.SaveChanges();
         }
         catch
         {
             //bład nie da sue usunać
         }
         return RedirectToAction("Index");
     }
 }
        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 MultikinoDb())
                {
                    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);
        }