public async Task <object> Update(JObject body) { try { Panduan panduanRequest = body.Value <JObject>("Panduan").ToObject <Panduan>(); Panduan panduanResponse = await panduanService.GetById(panduanRequest.IdPanduan); if (panduanResponse == null) { throw new NotFoundException("Panduan dengan ID tersebut tidak ditemukan"); } ExecuteResult result = await panduanService.InsertUpdate(panduanRequest); if (result.ReturnVariable <= 0) { throw new InternalServerErrorException("An error has occured"); } return(new { Status = Models.APIResult.ResultSuccessStatus, ReturnValue = result.ReturnVariable }); } catch (NotFoundException e) { throw e; } catch (Exception e) { throw new InternalServerErrorException(e.Message); } }
public async Task <object> Delete(int id) { try { Panduan panduan = await panduanService.GetById(id); if (panduan == null) { throw new NotFoundException("Panduan dengan ID tersebut tidak ditemukan"); } ExecuteResult result = await panduanService.Delete(id); if (result.ReturnVariable <= 0) { throw new InternalServerErrorException("An error has occured"); } return(new { Status = Models.APIResult.ResultSuccessStatus, ReturnValue = result.ReturnVariable }); } catch (NotFoundException e) { throw e; } catch (Exception e) { throw new InternalServerErrorException(e.Message); } }
public async Task <ActionResult> SaveDeskripsi(DescriptionViewModel descriptionViewModel) { try { Panduan panduan = await panduanService.GetById(descriptionViewModel.IdPanduan); if (ModelState.IsValid) { panduan.DeskripsiPanduan = descriptionViewModel.DeskripsiPanduan; int result = await panduanService.Update(panduan); ViewBag.ShowAlertTableBahan = 1; ViewBag.StatusAlert = "success"; ViewBag.MessageAlert = "Deskripsi Panduan berhasil diupdate"; } descriptionViewModel.IdPanduan = panduan.IdPanduan; descriptionViewModel.DeskripsiPanduan = panduan.DeskripsiPanduan; descriptionViewModel.IdUser = panduan.IdUser; return(PartialView("_Description", descriptionViewModel)); } catch (Exception e) { ViewBag.ShowAlertTableBahan = 1; ViewBag.StatusAlert = "error"; ViewBag.MessageAlert = e.Message; return(PartialView("_Description", descriptionViewModel)); } }
public async Task <ActionResult> _Description(int idPanduan) { Panduan panduan = await panduanService.GetById(idPanduan); DescriptionViewModel descriptionViewModel = new DescriptionViewModel { IdPanduan = panduan.IdPanduan, DeskripsiPanduan = panduan.DeskripsiPanduan, IdUser = panduan.IdUser }; return(PartialView(descriptionViewModel)); }
public async Task <ActionResult> _TableBahan(int idPanduan) { Panduan panduan = await panduanService.GetById(idPanduan); TableBahanViewModel tableBahanViewModel = new TableBahanViewModel { IdPanduan = idPanduan, IdUser = panduan.IdUser }; tableBahanViewModel.ListSelectedBahan = await bahanService.GetListByPanduan(idPanduan); await SetDropdownPartial(tableBahanViewModel); return(PartialView(tableBahanViewModel)); }
// GET: Panduan public async Task <ActionResult> Index(int id) { Panduan panduan = await panduanService.GetById(id); User user = await userService.GetById(panduan.IdUser); IndexViewModel indexViewModel = new IndexViewModel { IdPanduan = panduan.IdPanduan, NamaPanduan = panduan.NamaPanduan, UserName = user.Name, IdUser = user.IdUser }; return(View(indexViewModel)); }
public async Task <object> GetById(int id) { try { Panduan panduan = await panduanService.GetById(id); return(new { Status = Models.APIResult.ResultSuccessStatus, Panduan = panduan }); } catch (Exception e) { throw new InternalServerErrorException(e.Message); } }
public async Task <Panduan> GetById(int id) { HttpClient client = new APICall.HttpClientBuilder() .SetBaseURL(ConfigurationManager.AppSettings["API_BASE_URL"]) .SetMediaTypeWithQualityHeaderValue(APICall.APPLICATIONJSON) .Build(); var result = (await new APICall().Execute($"Panduan/{id}", client, HttpMethod.Get)).Data.ToString(); if (result.GetStatusCode() == 200) { JObject jObj = JObject.Parse(result); string panduanStr = jObj.SelectToken("Panduan").ToString(); Panduan panduan = JsonConvert.DeserializeObject <Panduan>(panduanStr); return(panduan); } string errMsg = result.GetStatusCode() + " " + result.GetStatusMessage() + " : " + result.GetMessage(); throw new Exception(errMsg); }
public async Task <JsonResult> _ChangeName(int id, string name) { try { if (String.IsNullOrEmpty(name)) { throw new Exception("Nama tidak boleh kosong"); } Panduan panduan = await panduanService.GetById(id); panduan.NamaPanduan = name; int result = await panduanService.Update(panduan); return(Json(new { status = "success", message = "", name = name })); } catch (Exception e) { return(Json(new { status = "error", message = e.Message })); } }
public async Task <ExecuteResult> InsertUpdate(Panduan Panduan) { ExecuteResult ReturnValue = new ExecuteResult(); List <StoredProcedure> Data = new List <StoredProcedure>(); Data.Add(new StoredProcedure { SPName = "Panduan_InsertUpdate @IdPanduan, @NamaPanduan, @DeskripsiPanduan, @IdUser", SQLParam = new SqlParameter[] { new SqlParameter("@IdPanduan", Panduan.IdPanduan), new SqlParameter("@NamaPanduan", Panduan.NamaPanduan), new SqlParameter("@DeskripsiPanduan", Panduan.DeskripsiPanduan), new SqlParameter("@IdUser", Panduan.IdUser), } }); ReturnValue = await panduanRepository.ExecMultipleSPWithTransaction(Data); return(ReturnValue); }
public async Task <object> Insert(JObject body) { try { Panduan panduanRequest = body.Value <JObject>("Panduan").ToObject <Panduan>(); ExecuteResult result = await panduanService.InsertUpdate(panduanRequest); if (result.ReturnVariable <= 0) { throw new InternalServerErrorException("An error has occured"); } return(new { Status = Models.APIResult.ResultSuccessStatus, ReturnValue = result.ReturnVariable }); } catch (Exception e) { throw new InternalServerErrorException(e.Message); } }
public async Task <int> Update(Panduan panduan) { HttpClient client = new APICall.HttpClientBuilder() .SetBaseURL(ConfigurationManager.AppSettings["API_BASE_URL"]) .SetMediaTypeWithQualityHeaderValue(APICall.APPLICATIONJSON) .Build(); Dictionary <string, dynamic> Body = new Dictionary <string, dynamic>(); Body.Add("Panduan", panduan); var result = (await new APICall().Execute($"Panduan", client, HttpMethod.Put, Body)).Data.ToString(); if (result.GetStatusCode() == 200) { JObject jObj = JObject.Parse(result); string ReturnValueStr = jObj.SelectToken("ReturnValue").ToString(); int id = JsonConvert.DeserializeObject <int>(ReturnValueStr); return(id); } string errMsg = result.GetStatusCode() + " " + result.GetStatusMessage() + " : " + result.GetMessage(); throw new Exception(errMsg); }