public async Task <APIResult <bool> > Edit(int IDBP, BoPhanUpdateRequest request) { var bp = await _context.BoPhans.FirstOrDefaultAsync(x => x.IDBP == IDBP); bp.TenBP = request.TenBP; await _context.SaveChangesAsync(); return(new APISuccessedResult <bool>(true)); }
public async Task <IActionResult> Edit(int IDBP, BoPhanUpdateRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await _boPhanServices.Edit(IDBP, request); if (result.ResultObj == true) { return(Ok(result)); } return(BadRequest(result)); }
public async Task <IActionResult> Edit(BoPhanUpdateRequest request) { if (!ModelState.IsValid) { return(View(ModelState)); } var result = await _boPhanApiClient.Edit(request.IDBP, request); if (result.IsSuccessed) { TempData["result"] = "Sửa bộ phận chức vụ thành công!"; return(RedirectToAction("Index")); } return(RedirectToAction("Error", "Home")); }
public async Task <APIResult <bool> > Edit(int IDBP, BoPhanUpdateRequest request) { var client = _httpClientFactory.CreateClient(); client.BaseAddress = new Uri(_configuration["BaseAddress"]); var json = JsonConvert.SerializeObject(request); var httpContent = new StringContent(json, Encoding.UTF8, "application/json"); var reponse = await client.PutAsync($"/api/BoPhans/{IDBP}/edit", httpContent); if (reponse.IsSuccessStatusCode) { return(JsonConvert.DeserializeObject <APISuccessedResult <bool> >(await reponse.Content.ReadAsStringAsync())); } return(JsonConvert.DeserializeObject <APIErrorResult <bool> >(await reponse.Content.ReadAsStringAsync())); }
public async Task <IActionResult> Edit(int IDBP) { if (!ModelState.IsValid) { return(View(ModelState)); } var result = await _boPhanApiClient.Details(IDBP); var bpUpdateRequest = new BoPhanUpdateRequest() { IDBP = result.ResultObj.IDBP, TenBP = result.ResultObj.TenBP }; return(View(bpUpdateRequest)); }