示例#1
0
 public ActionResult DoTwint(Twint input)
 {
     if (Session["User"] == null)
     {
         return RedirectToAction("Login", "Account");
     }
     if (ModelState.IsValid)
     {
         //
         db.twints.Add(input);
         db.SaveChanges();
         var LastTwintId = db.twints.Select(t => t.Twint_Id).Max();
         db.UserTwints.Add(new UserTwint { User_Id = Int32.Parse(Session["UserId"].ToString()), Twint_Id = LastTwintId });
         db.SaveChanges();
         //
         ModelState.Clear();
         //
         return RedirectToAction("Index/" + Session["UserId"].ToString(), "Home");
     }
     return View();
 }
示例#2
0
        public ActionResult Register(User input)
        {
            if (ModelState.IsValid)
            {
                using (twinterContext db = new twinterContext())
                {
                    db.users.Add(input);
                    db.SaveChanges();
                }
                ModelState.Clear();
                ViewBag.Message = input.User1 + " has been registered successfuly!";

                if (Session["User"] != null)
                {
                    return(RedirectToAction("Logout"));
                }
                using (twinterContext db = new twinterContext())
                {
                    var usr = db.users.Where(u => u.email == input.email && u.password == input.password).FirstOrDefault();
                    if (usr != null)
                    {
                        Session["UserId"]   = usr.User_Id.ToString();
                        Session["User"]     = usr.User1.ToString();
                        Session["Role"]     = usr.Role.ToString();
                        Session["Email"]    = usr.email.ToString();
                        Session["Password"] = usr.password.ToString();

                        switch (Int16.Parse(Session["Role"].ToString()))
                        {
                        case Constants.main_administrator:
                            return(RedirectToAction("Index", "MainAdmin"));

                        case Constants.administrator:
                            break;

                        case Constants.moderator:
                            break;

                        default:
                            break;
                        }
                        return(RedirectToAction("LoggedIn"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "The Email or/and the Password are wrong!");
                    }
                }
            }
            return(View());
        }