public async Task <JsonResult> ChangeStatus(string id)
        {
            if (Session["Authent"] != null)
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(Baseurl);

                    client.DefaultRequestHeaders.Clear();
                    //Define request data format

                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Session["Authent"].ToString());
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    var userActive = new activeUser();
                    userActive.user_id = long.Parse(id);

                    HttpResponseMessage Res = await client.GetAsync($"admin/users/{id}");

                    var EmpResponse2 = Res.Content.ReadAsStringAsync().Result;
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    var item = serializer.Deserialize <dynamic>(EmpResponse2)["data"];
                    userActive.status_active = !item["is_activated"];
                    //HTTP POST
                    var response = await client.PostAsync("admin/users/toggle-active", new StringContent(
                                                              new JavaScriptSerializer().Serialize(userActive), Encoding.UTF8, "application/json"));

                    //HttpResponseMessage Res = await client.GetAsync("/users");
                    var EmpResponse = await response.Content.ReadAsStringAsync();

                    int code   = Convert.ToInt32(serializer.Deserialize <dynamic>(EmpResponse)["code"]);
                    int status = Convert.ToInt32(serializer.Deserialize <dynamic>(EmpResponse)["status"]);
                    if (code != 200)
                    {
                        return(Json(new { result = false, mess = serializer.Deserialize <dynamic>(EmpResponse)["message"] }));
                    }
                    if (response.IsSuccessStatusCode && status == 1)
                    {
                        return(Json(new { result = true, status = userActive.status_active, mess = serializer.Deserialize <dynamic>(EmpResponse)["message"] }));
                    }

                    return(Json(new { result = false, mess = "error create user" }));
                }
            }
            return(Json(new { result = false, mess = "ko co quyen" }));
        }
Beispiel #2
0
        public async Task <JsonResult> ChangeStatusXacNhanHoanThanh(string id, string code)
        {
            if (Session["Authent"] != null)
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(Baseurl);

                    client.DefaultRequestHeaders.Clear();
                    //Define request data format

                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Session["Authent"].ToString());
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    var userActive = new activeUser();
                    userActive.user_id = long.Parse(id);

                    JavaScriptSerializer serializer = new JavaScriptSerializer();

                    //HTTP POST
                    var response = await client.PostAsync($"/manager/booking/verify-finished?id={id}&code={code}", new StringContent(
                                                              new JavaScriptSerializer().Serialize(userActive), Encoding.UTF8, "application/json"));

                    //HttpResponseMessage Res = await client.GetAsync("/users");
                    var EmpResponse = await response.Content.ReadAsStringAsync();

                    int code2  = Convert.ToInt32(serializer.Deserialize <dynamic>(EmpResponse)["code"]);
                    int status = Convert.ToInt32(serializer.Deserialize <dynamic>(EmpResponse)["status"]);
                    if (code2 != 200)
                    {
                        return(Json(new { result = false, mess = serializer.Deserialize <dynamic>(EmpResponse)["message"] }));
                    }
                    if (response.IsSuccessStatusCode && status == 1)
                    {
                        return(Json(new { result = true, mess = serializer.Deserialize <dynamic>(EmpResponse)["message"] }));
                    }

                    return(Json(new { result = false, mess = "Lỗi xác nhận thanh toán" }));
                }
            }
            return(Json(new { result = false, mess = "ko co quyen" }));
        }