public ActionResult AddDaftarAlat(string paramAll) { object result = null; try { if (paramAll == null) { paramAll = ""; } string namaAlat = paramAll; HttpClient client = new HttpClient(); string baseUrl = Url.Action("", "", null, HttpContext.Request.Scheme); client.BaseAddress = new Uri(baseUrl); var text = client.GetStringAsync("api/DaftarAlatApi/GetList").Result; var resultDaftarAlat = JsonConvert.DeserializeObject <List <DaftarAlatEntity.DaftarAlat> >(text); int countNamaAlat = resultDaftarAlat.Where(x => x.NamaAlat == namaAlat.Trim()).Count(); if (string.IsNullOrEmpty(namaAlat)) { result = new { error = "1" } } ; else if (countNamaAlat > 0) { result = new { error = "2" } } ; else { // Add PersiapanAlat DaftarAlatEntity.DaftarAlat daftarAlatInfo = new DaftarAlatEntity.DaftarAlat(); daftarAlatInfo.NamaAlat = namaAlat; daftarAlatInfo.Desc = ""; daftarAlatInfo.CreatedDate = DateTime.Now; daftarAlatInfo.CreatedBy = "System"; daftarAlatInfo.UpdatedDate = null; daftarAlatInfo.UpdatedBy = null; var jsonString = JsonConvert.SerializeObject(daftarAlatInfo); var putTask = client.PostAsync("api/DaftarAlatApi/CreateNew", new StringContent(jsonString, System.Text.Encoding.UTF8, "application/json")); putTask.Wait(); result = new { error = "0" }; } } catch (Exception ex) { Log.WriteLog(ex.Message, hosting); } return(Json(result)); }
public void Post([FromBody] DaftarAlatEntity.DaftarAlat daftarAlat) { context.Entry(daftarAlat).State = EntityState.Added; context.DaftarAlats.Add(daftarAlat); context.SaveChanges(); CreatedAtAction(nameof(daftarAlat), new { id = daftarAlat.ID }, daftarAlat); }
public void Put(long id, [FromBody] DaftarAlatEntity.DaftarAlat daftarAlat) { if (id != daftarAlat.ID) { BadRequest(); return; } context.Entry(daftarAlat).State = EntityState.Modified; context.Update(daftarAlat); context.SaveChanges(); }