コード例 #1
0
        private void saveInSession(string response)
        {
            AuthModel authModel = AuthModel.FromJson(response);

            SaveToken(authModel);
            SaveRefreshToken(authModel);
        }
コード例 #2
0
        public static bool CreateEvent(string name, string image, CategoryModel[] categories, string start, string end, string address, string referenceLocation, Zone[] zona)
        {
            const string endpoint = "events/";
            var          client   = new RestClient(URL);
            var          request  = new RestRequest(endpoint, Method.POST);

            string jsonToSend = SerializeEvent.ToJson(new EventModel
            {
                Name       = name,
                Image      = image,
                Categories =
                {
                },
                Start             = start,
                End               = end,
                Address           = address,
                ReferenceLocation = referenceLocation,
                Zones             =
                {
                },
            });

            request.AddParameter("application/json; charset=utf-8", jsonToSend, ParameterType.RequestBody);
            request.RequestFormat = DataFormat.Json;

            bool success = false;

            try
            {
                IRestResponse response = client.Execute(request);
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    AuthModel authModel = AuthModel.FromJson(response.Content.ToString());
                    //SaveToken(authModel);
                    //SaveRefreshToken(authModel);
                    success = true;
                }
                else
                {
                    // NOK
                    Console.Write(response.ToString());
                }
            }
            catch (Exception error)
            {
                Console.Write(error.ToString());
            }

            return(success);
        }
コード例 #3
0
        public static bool RegisterShopper(string username, string firstname, string lastname, string email, string password)
        {
            const string endpoint = "auth/shoppers";
            var          client   = new RestClient(URL);
            var          request  = new RestRequest(endpoint, Method.POST);

            string jsonToSend = SerializeUser.ToJson(new UserModel
            {
                Username  = username,
                Password  = password,
                Email     = email,
                Firstname = firstname,
                Lastname  = lastname
            });

            request.AddParameter("application/json; charset=utf-8", jsonToSend, ParameterType.RequestBody);
            request.RequestFormat = DataFormat.Json;

            bool success = false;

            try
            {
                IRestResponse response = client.Execute(request);
                if (response.StatusCode == HttpStatusCode.Created)
                {
                    AuthModel authModel = AuthModel.FromJson(response.Content.ToString());
                    //SaveToken(authModel);
                    //SaveRefreshToken(authModel);
                    success = true;
                }
                else
                {
                    // NOK
                    Console.Write(response.ToString());
                }
            }
            catch (Exception error)
            {
                Console.Write(error.ToString());
            }

            return(success);
        }