public ActionResult Create(Message msg)
 {
     if (ModelState.IsValid)
     {
         db.Messages.Add(msg);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(msg));
 }
        public ActionResult Delete(int id)
        {
            Message gstbk = db.Messages.Find(id);

            db.Messages.Remove(gstbk);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #3
0
 public ActionResult ChangeProfile(RegisterModel model)
 {
     using (TAS_SIUKDWStoreContext db = new TAS_SIUKDWStoreContext())
     {
         var currUser = (from u in db.UserProfiles
                         where u.UserName == model.UserName
                         select u).FirstOrDefault();
         if (currUser != null)
         {
             currUser.FullName = model.FullName;
             currUser.Address  = model.Address;
             currUser.Email    = model.Email;
             db.SaveChanges();
         }
     }
     return(RedirectToAction("Manage"));
 }
Exemple #4
0
        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 (TAS_SIUKDWStoreContext db = new TAS_SIUKDWStoreContext())
                {
                    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));
        }
Exemple #5
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password);

                    using (TAS_SIUKDWStoreContext db = new TAS_SIUKDWStoreContext())
                    {
                        var currUser = (from c in db.UserProfiles
                                        where c.UserName == model.UserName
                                        select c).SingleOrDefault();

                        if (currUser != null)
                        {
                            currUser.FullName = model.FullName;

                            currUser.Address = model.Address;
                            currUser.Email   = model.Email;
                            db.SaveChanges();
                        }
                    }

                    WebSecurity.Login(model.UserName, model.Password);
                    return(RedirectToAction("Index", "Home"));
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }