Ejemplo n.º 1
0
        public JsonResult Login(string email, string password)
        {
            var result = false;

            if (ModelState.IsValid)
            {
                using (NhaTroEntities db = new NhaTroEntities())
                {
                    var obj = db.User.Where(a => a.Email == email && a.Password == password).FirstOrDefault();
                    if (obj != null)
                    {
                        Session["UserID"]   = Convert.ToInt32(obj.Id.ToString());
                        Session["UserName"] = obj.LoginId.ToString();
                        Session["Email"]    = obj.Email.ToString();
                        Session["Balance"]  = obj.Balance;
                        if (obj.IsActive == 1)
                        {
                            Session["IsAdmin"] = obj.IsActive;
                        }

                        result = true;
                    }
                    else
                    {
                        result = false;
                    }
                }
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public JsonResult SignUp(User user)
        {
            var result     = false;
            var checkEmail = true;

            if (ModelState.IsValid)
            {
                using (NhaTroEntities db = new NhaTroEntities())
                {
                    var userByEmail = (from u in db.User
                                       where u.Email == user.Email
                                       select u).FirstOrDefault();
                    if (userByEmail != null)
                    {
                        checkEmail = false;
                    }

                    else
                    {
                        try
                        {
                            User users = new User();
                            users.LoginId  = user.LoginId;
                            users.Phone    = user.Phone;
                            users.Email    = user.Email;
                            users.Password = user.Password;
                            db.User.Add(users);
                            db.SaveChanges();
                            result = true;
                        }

                        catch
                        {
                            result = false;
                        }
                    }
                }
            }

            return(Json(new { result, checkEmail }, JsonRequestBehavior.AllowGet));
        }