Ejemplo n.º 1
0
        public int CreateAccount(TaiKhoan tk)
        {
            if (IsUsernameExist(tk.TenDangNhap))
            {
                return RegisterState.UsernameExist;
            }
            try
            {
                Membership.CreateUser(tk.TenDangNhap, tk.MatKhau, tk.Email);
                db.TaiKhoans.Add(tk);
                db.SaveChanges();
                if (!Roles.RoleExists("User"))
                {
                    CreateRole("User");
                }
                Roles.AddUserToRole(tk.TenDangNhap, "User");
            }
            catch (Exception)
            {
                return RegisterState.Error;
            }

            return RegisterState.Success;
        }
Ejemplo n.º 2
0
        public bool UpdateAccount(TaiKhoan acc)
        {
            TaiKhoan tk = db.TaiKhoans.Find(acc.TenDangNhap);
            if (tk != null)
            {
                try
                {
                    db.Entry(tk).State = EntityState.Modified;
                    db.SaveChanges();

                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }

            return false;
        }