public ActionResult TambaheditData(int id = 0)
        {
            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(Helpers.RestAPIAddress.GetUrl());
                if (id == 0)
                {
                    return(View(new KatBarang()));
                }
                else
                {
                    client.DefaultRequestHeaders.Authorization =
                        new AuthenticationHeaderValue("Bearer",
                                                      HttpContext.Session.GetString("JWTtoken"));
                    var token = HttpContext.Session.GetString("JWTtoken");
                    HttpResponseMessage response = client.GetAsync("/api/KatBarang/" + id).Result;
                    if (response.StatusCode == HttpStatusCode.BadRequest || response.StatusCode == HttpStatusCode.Forbidden)
                    {
                        return(Redirect("/Home/ERROR403"));
                    }
                    string    stringData = response.Content.ReadAsStringAsync().Result;
                    KatBarang data       = JsonConvert.DeserializeObject <KatBarang>(stringData);

                    TempData["Pesan"] = "Saved Successfully";
                    return(View(data));
                }
            }
        }
        // GET: KatBarang
        public ActionResult Index(KatBarang kat_barang)
        {
            using (HttpClient client = new HttpClient())
            {
                //client.BaseAddress = new Uri("http://localhost:30512");

                //client.DefaultRequestHeaders.Authorization =
                //new AuthenticationHeaderValue("Bearer",
                //HttpContext.Session.GetString("JWTtoken"));
                //var token = HttpContext.Session.GetString("JWTtoken");


                //MediaTypeWithQualityHeaderValue contentType = new MediaTypeWithQualityHeaderValue("application/json");
                //client.DefaultRequestHeaders.Accept.Add(contentType);
                //HttpResponseMessage response = client.GetAsync("/api/KatBarang").Result;
                //if (response.StatusCode == HttpStatusCode.BadRequest || response.StatusCode == HttpStatusCode.Forbidden)
                //{
                //    return Redirect("/Home/ERROR403");
                //}
                //string stringData = response.Content.ReadAsStringAsync().Result;

                //List<KatBarang> data = JsonConvert.DeserializeObject<List<KatBarang>>(stringData);
                return(View());
            }
        }
예제 #3
0
        // GET: KatBarang
        public ActionResult Index(KatBarang kat_barang)
        {
            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:30512");

                client.DefaultRequestHeaders.Authorization =
                    new AuthenticationHeaderValue("Bearer",
                                                  HttpContext.Session.GetString("JWTtoken"));
                var token = HttpContext.Session.GetString("JWTtoken");


                MediaTypeWithQualityHeaderValue contentType = new MediaTypeWithQualityHeaderValue("application/json");
                client.DefaultRequestHeaders.Accept.Add(contentType);
                HttpResponseMessage response = client.GetAsync("/api/KatBarang").Result;
                string stringData            = response.Content.ReadAsStringAsync().Result;
                if (response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    return(Redirect("/Home/UnAuthorized"));
                }

                List <KatBarang> data = JsonConvert.DeserializeObject <List <KatBarang> >(stringData);
                //Aku lupa ini buat apa ?
                //var test = data.FirstOrDefault().Tenant.TenantName;
                //HttpContext.Session.SetString("datatenant", test);
                //var datatenant = HttpContext.Session.GetString("datatenant");
                return(View(data));
            }
        }
        //TIDAK BISA CREATE JIKA DATA KATBARANG DI TENANT YANG SAMA
        public async Task <IActionResult> Post([FromBody] KatBarang KatBarang)
        {
            try
            {
                await _KatBarang.CreateAsync(KatBarang);

                return(Ok("Tambah Data Berhasil"));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public async Task <IActionResult> Put([FromBody] KatBarang KatBarang)
        {
            try
            {
                await _KatBarang.UpdateAsync(KatBarang);

                return(Ok("Data berhasil diupdate"));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
예제 #6
0
        public ActionResult TambahEditData(KatBarang obj)
        {
            if (ModelState.IsValid)
            {
                using (HttpClient client = new HttpClient())
                {
                    client.BaseAddress = new Uri("http://localhost:30512");
                    if (obj.IdKategori == 0)
                    {
                        client.DefaultRequestHeaders.Authorization =
                            new AuthenticationHeaderValue("Bearer",
                                                          HttpContext.Session.GetString("JWTtoken"));
                        var    token                 = HttpContext.Session.GetString("JWTtoken");
                        string stringData            = JsonConvert.SerializeObject(obj);
                        var    contentData           = new StringContent(stringData, System.Text.Encoding.UTF8, "application/json");
                        HttpResponseMessage response = client.PostAsync("/api/KatBarang", contentData).Result;
                        if (response.IsSuccessStatusCode)
                        {
                            TempData["success"] = "success";
                            TempData["Pesan"]   = response.Content.ReadAsStringAsync().Result;
                        }
                        else
                        {
                            TempData["error"] = "error";
                            TempData["Pesan"] = response.Content.ReadAsStringAsync().Result;
                        }
                        //var data1 = response.Content.ReadAsStringAsync().Result.ToList().ToString();
                    }
                    else
                    {
                        string stringData            = JsonConvert.SerializeObject(obj);
                        var    contentData           = new StringContent(stringData, System.Text.Encoding.UTF8, "application/json");
                        HttpResponseMessage response = client.PutAsync("/api/KatBarang/" + obj.IdKategori, contentData).Result;
                        if (response.IsSuccessStatusCode)
                        {
                            TempData["success"] = "success";
                            TempData["Pesan"]   = response.Content.ReadAsStringAsync().Result;
                        }
                        else
                        {
                            TempData["error"] = "error";
                            TempData["Pesan"] = response.Content.ReadAsStringAsync().Result;
                        }
                    }
                }
            }

            return(RedirectToAction("Index"));
        }
 public ActionResult TambahEditData(int id = 0)
 {
     using (HttpClient client = new HttpClient())
     {
         client.BaseAddress = new Uri("http://localhost:30512");
         if (id == 0)
         {
             return(View(new Barang()));
         }
         else
         {
             HttpResponseMessage response = client.GetAsync("/api/Barang/" + id).Result;
             string    stringData         = response.Content.ReadAsStringAsync().Result;
             KatBarang data = JsonConvert.DeserializeObject <KatBarang>(stringData);
             TempData["SuccessMessage"] = "Saved Successfully";
             return(View(data));
         }
     }
 }
예제 #8
0
        public async Task CreateAsync(KatBarang obj)
        {
            //How to convert System.Linq.Enumerable.WhereListIterator<int> to List<int>?
            //mencari data tenant "ccc"
            //result dengan mencari dari hasil search tenant
            var data = await getbytenantid(obj.TenantID);

            var result = data.Where(e => e.NamaKategori == obj.NamaKategori).ToList();

            //mencari data tenant ccc
            if (result.Count == 0)
            {
                _context.Add(obj);
                await _context.SaveChangesAsync();
            }
            else
            {
                throw new Exception("Nama Kategori tidak boleh sama");
            }
        }
예제 #9
0
        public async Task UpdateAsync(KatBarang obj)
        {
            var data = await GetById(obj.IdKategori);

            if (data != null)
            {
                try
                {
                    data.NamaKategori = obj.NamaKategori;
                    data.TenantID     = obj.TenantID;
                    await _context.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    throw new Exception($"{ex.Message} {ex.InnerException.Message}");
                }
            }
            else
            {
                throw new Exception("Data tidak ditemukan");
            }
        }
예제 #10
0
 public ActionResult TambaheditData(int id = 0)
 {
     using (HttpClient client = new HttpClient())
     {
         client.BaseAddress = new Uri("http://localhost:30512");
         if (id == 0)
         {
             return(View(new KatBarang()));
         }
         else
         {
             client.DefaultRequestHeaders.Authorization =
                 new AuthenticationHeaderValue("Bearer",
                                               HttpContext.Session.GetString("JWTtoken"));
             var token = HttpContext.Session.GetString("JWTtoken");
             HttpResponseMessage response = client.GetAsync("/api/KatBarang/" + id).Result;
             string    stringData         = response.Content.ReadAsStringAsync().Result;
             KatBarang data = JsonConvert.DeserializeObject <KatBarang>(stringData);
             TempData["Pesan"] = "Saved Successfully";
             return(View(data));
         }
     }
 }
        public ActionResult TambahEditData(KatBarang obj)
        {
            if (obj.TenantID == null)
            {
                obj.Tenant   = null;
                obj.TenantID = HttpContext.Session.GetString("TenantID");
            }
            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(Helpers.RestAPIAddress.GetUrl());
                if (obj.IdKategori == 0)
                {
                    client.DefaultRequestHeaders.Authorization =
                        new AuthenticationHeaderValue("Bearer",
                                                      HttpContext.Session.GetString("JWTtoken"));
                    var    token                 = HttpContext.Session.GetString("JWTtoken");
                    string stringData            = JsonConvert.SerializeObject(obj);
                    var    contentData           = new StringContent(stringData, System.Text.Encoding.UTF8, "application/json");
                    HttpResponseMessage response = client.PostAsync("/api/KatBarang", contentData).Result;
                    if (response.StatusCode == HttpStatusCode.Forbidden)
                    {
                        return(Redirect("/Home/ERROR403"));
                    }
                    if (response.StatusCode == HttpStatusCode.BadRequest)
                    {
                        TempData["error"] = "error";
                        TempData["Pesan"] = response.Content.ReadAsStringAsync().Result;
                        return(Redirect("/Barang/barangtenantid?tenantID=" + HttpContext.Session.GetString("TenantID")));
                    }
                    if (response.IsSuccessStatusCode)
                    {
                        TempData["success"] = "success";
                        TempData["Pesan"]   = response.Content.ReadAsStringAsync().Result;
                    }
                    else
                    {
                        TempData["error"] = "error";
                        TempData["Pesan"] = response.Content.ReadAsStringAsync().Result;
                    }

                    return(Redirect("/KatBarang/KatBarangbytenant?tenantID=" + HttpContext.Session.GetString("TenantID")));

                    //var data1 = response.Content.ReadAsStringAsync().Result.ToList().ToString();
                }
                else
                {
                    client.DefaultRequestHeaders.Authorization =
                        new AuthenticationHeaderValue("Bearer",
                                                      HttpContext.Session.GetString("JWTtoken"));
                    var    token                 = HttpContext.Session.GetString("JWTtoken");
                    string stringData            = JsonConvert.SerializeObject(obj);
                    var    contentData           = new StringContent(stringData, System.Text.Encoding.UTF8, "application/json");
                    HttpResponseMessage response = client.PutAsync("/api/KatBarang/" + obj.IdKategori, contentData).Result;
                    if (response.StatusCode == HttpStatusCode.BadRequest || response.StatusCode == HttpStatusCode.Forbidden)
                    {
                        return(Redirect("/Home/ERROR403"));
                    }
                    if (response.IsSuccessStatusCode)
                    {
                        TempData["success"] = "success";
                        TempData["Pesan"]   = response.Content.ReadAsStringAsync().Result;
                    }
                    else
                    {
                        TempData["error"] = "error";
                        TempData["Pesan"] = response.Content.ReadAsStringAsync().Result;
                    }
                    return(Redirect("/KatBarang/KatBarangbytenant?tenantID=" + HttpContext.Session.GetString("TenantID")));
                }
            }
        }