public async Task <IActionResult> Edit(QLNghiPhepUpdateRequest request) { var result = await _qLNghiPhepApiClient.Edit(request.IDNP, request); if (result.IsSuccessed) { TempData["result"] = "Sửa nghỉ phép thành công!"; return(RedirectToAction("Index")); } return(RedirectToAction("Error", "Home")); }
public async Task <IActionResult> Edit(int IDNP, QLNghiPhepUpdateRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await _qLNghiPhepServices.Edit(IDNP, request); if (result.IsSuccessed) { return(Ok(result)); } return(BadRequest(result)); }
public async Task <APIResult <bool> > Edit(int IDNP, QLNghiPhepUpdateRequest 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 response = await client.PutAsync($"/api/QLNghiPheps/{IDNP}/edit", httpContent); var body = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { return(JsonConvert.DeserializeObject <APISuccessedResult <bool> >(body)); } return(JsonConvert.DeserializeObject <APIErrorResult <bool> >(body)); }
public async Task <IActionResult> Edit(int IDNP) { if (!ModelState.IsValid) { return(View(ModelState)); } var qlnpDetails = await _qLNghiPhepApiClient.Details(IDNP); var qlnpUpdateRequest = new QLNghiPhepUpdateRequest() { IDNP = qlnpDetails.ResultObj.IDNP, IDSQ = qlnpDetails.ResultObj.IDSQ, HoTen = qlnpDetails.ResultObj.HoTen, ThoiGianBDNP = qlnpDetails.ResultObj.ThoiGianBDNP, ThoiGianKTNP = qlnpDetails.ResultObj.ThoiGianKTNP, NghiPhepState = qlnpDetails.ResultObj.NghiPhepState }; return(View(qlnpUpdateRequest)); }
public async Task <APIResult <bool> > Edit(int IDNP, QLNghiPhepUpdateRequest request) { var qlnp = await _context.QLNghiPheps.FirstOrDefaultAsync(x => x.IDNP == IDNP); if (DateTime.Compare(request.ThoiGianBDNP, request.ThoiGianKTNP) > 0) { return(new APIErrorResult <bool>("Thất bại")); } qlnp.ThoiGianBDNP = request.ThoiGianBDNP; qlnp.ThoiGianKTNP = request.ThoiGianKTNP; if ((DateTime.Compare(request.ThoiGianBDNP, DateTime.Now) < 0) && (DateTime.Compare(request.ThoiGianKTNP, DateTime.Now) >= 0)) { qlnp.NghiPhepState = 1; } else { qlnp.NghiPhepState = 0; } await _context.SaveChangesAsync(); return(new APISuccessedResult <bool>(true)); }