コード例 #1
0
        public ActionResult Create([Bind(Include = "id,username,password,question,answer,roldId,firstName,lasName,gender,country,mobile,address")] Account account)
        {
            var i = db.Accounts.Count(acc => acc.username.Equals(account.username));

            if (ModelState.IsValid)
            {
                if (i < 1)
                {
                    AccountViewModels avm = new AccountViewModels();
                    avm.accountView           = new Account();
                    avm.accountView.username  = account.username;
                    avm.accountView.password  = EncryptMD5.Encrypt(account.password);
                    avm.accountView.question  = account.question;
                    avm.accountView.answer    = account.answer;
                    avm.accountView.roldId    = account.roldId;
                    avm.accountView.firstName = account.firstName;
                    avm.accountView.lastName  = account.lastName;
                    avm.accountView.gender    = account.gender;
                    avm.accountView.country   = account.country;
                    avm.accountView.mobile    = account.mobile;
                    avm.accountView.address   = account.address;


                    db.Accounts.Add(avm.accountView);
                    db.SaveChanges();
                    return(View("Index"));
                }
                ModelState.AddModelError("", "UserName Has been used");
            }

            ViewBag.roldId = new SelectList(db.Roles, "id", "name", account.roldId);
            return(View(account));
        }
コード例 #2
0
        public ActionResult MyProfile(Account account)
        {
            AccountViewModels avm = new AccountViewModels()
            {
                accountView = new Account()
                {
                    id        = account.id,
                    username  = MySession.Username,
                    password  = EncryptMD5.Encrypt(account.password),
                    question  = account.question,
                    answer    = account.answer,
                    roldId    = account.roldId,
                    firstName = account.firstName,
                    lastName  = account.lastName,
                    gender    = account.gender,
                    country   = account.country,
                    mobile    = account.mobile,
                    address   = account.address
                }
            };

            db.Entry(avm.accountView).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
コード例 #3
0
        //[MultipleButton(Name = "action", Argument = "Edit")]

        public ActionResult Edit([Bind(Include = "username,password,question,answer,roldId,firstName,lasName,gender,country,mobile,address")] Account account)
        {
            //ProjectWebGreeting.Common.EncryptMD5.Decrypt(account.password);
            if (ModelState.IsValid)
            {
                AccountViewModels avm = new AccountViewModels()
                {
                    accountView = new Account()
                    {
                        username  = account.username,
                        password  = EncryptMD5.Encrypt(account.password),
                        question  = account.question,
                        answer    = account.answer,
                        roldId    = account.roldId,
                        firstName = account.firstName,
                        lastName  = account.lastName,
                        gender    = account.gender,
                        country   = account.country,
                        mobile    = account.mobile,
                        address   = account.address
                    }
                };
                db.Entry(avm.accountView).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.roldId = new SelectList(db.Roles, "id", "name", account.roldId);
            return(View(account));
        }
コード例 #4
0
        public ActionResult Login(string username, string password)
        {
            string passwordmd5 = EncryptMD5.Encrypt(password);
            var    user        = db.Administrators.SingleOrDefault(x => x.UserName == username && x.PassWord == passwordmd5 && x.Allowed == 1);

            if (user != null)
            {
                Session["userid"]   = user.UserID;
                Session["username"] = user.UserName;
                Session["fullname"] = user.FullName;
                Session["avatar"]   = user.Avatar;
                return(RedirectToAction("Index"));
            }
            ViewBag.Error = "Đăng nhập sai cmmr!";
            return(View());
        }
コード例 #5
0
        public ActionResult Login(Account account)
        {
            var pas    = EncryptMD5.Encrypt(account.password);
            var result = db.Accounts.Count(a => a.username.Equals(account.username) && a.password.Equals(pas));

            //var result = db.Accounts.Count(a => a.username.Equals(account.username) && a.password.Equals(pas));
            if (result > 0)
            {
                MySession.Username = account.username;
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ViewBag.error = "Account's Invalid";
                return(View("Login", new Account()));
            }
        }