Exemplo n.º 1
0
        public JsonResult AddUser(FormCollection data)
        {
            string username = data["username"];
            string password = data["password"];

            JsonResult json = new JsonResult();

            if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password))
            {
                json.Data = new
                {
                    status  = "ERROR",
                    message = "Data cannot be empty"
                };
            }
            else
            {
                DBIO  db   = new DBIO();
                Users user = new Users();

                user.ID       = db.GetLatestID() + 1;
                user.username = username;
                user.password = password;
                db.AddObject(user);
                db.Save();
                json.Data = new
                {
                    status = "OK"
                };
            }

            return(Json(json, JsonRequestBehavior.AllowGet));
        }