Exemple #1
0
        public async Task <Boolean> UpdateApp(string Id, AppCreateModel appCreateModel)
        {
            using (var client = new HttpClient())
            {
                ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
                var requestUri = new Uri(WebConfigurationManager.AppSettings["OneSignalEndPoint"] + $"/{Id}");

                client.BaseAddress = requestUri;
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", WebConfigurationManager.AppSettings["AuthToken"]);
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                var payload = new StringContent(JsonConvert.SerializeObject(appCreateModel), Encoding.UTF8, "application/json");

                //HTTP POST
                var result = await client.PutAsync(requestUri, payload);

                if (result.IsSuccessStatusCode)
                {
                    return(true);
                }
                else //web api sent error response
                {
                    return(false);
                }
            }
        }
        public async Task <ActionResult> Create(AppCreateModel appCreateModel)
        {
            if (ModelState.IsValid)
            {
                var isCreated = await AppService.CreateApp(appCreateModel);

                if (isCreated)
                {
                    return(RedirectToAction("Index"));
                }

                ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Invalid Request.");
            }

            ViewBag.IsAdmin = IsAdminUser();
            return(View(appCreateModel));
        }