Exemple #1
0
        public JsonResult Get(string id)
        {
            try
            {
                Staff data = dao.Get(id);

                return(Json(new
                {
                    data = data
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(new
                {
                    data = DBNull.Value.ToString()
                }, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult Login(string username, string password, int type = 0)
        {
            if (type == 0)
            {
                StudentDAO dao = new StudentDAO();

                int status = dao.Login(username, Encryptor.MD5Hash(password));
                if (status == 1)
                {
                    var student = dao.Get(username);
                    var user    = new User();
                    user.Username = student.Id;
                    user.Avatar   = student.Avatar;
                    user.FullName = student.FullName;
                    user.Gender   = student.Gender;

                    Session[Constants.USER] = user;

                    return(Json(new
                    {
                        status = status,
                        data = student
                    }));
                }
                else
                {
                    return(Json(new
                    {
                        status = status
                    }));
                }
            }
            else if (type == 1)
            {
                StaffDAO dao = new StaffDAO();

                int status = dao.Login(username, Encryptor.MD5Hash(password));
                if (status == 1)
                {
                    var staff = dao.Get(username);
                    var user  = new User();
                    user.Username = staff.Id;
                    user.Avatar   = staff.Avatar;
                    user.FullName = staff.FullName;
                    user.Gender   = staff.Gender;

                    Session[Constants.ADMIN] = user;

                    return(Json(new
                    {
                        status = status,
                        data = staff
                    }));
                }
                else
                {
                    return(Json(new
                    {
                        status = status
                    }));
                }
            }
            else
            {
                return(Json(new
                {
                    status = -1
                }));
            }
        }