Пример #1
0
        public IActionResult UpdateLadingCode(int id, string lading_code)
        {
            var request = new UpdateLadingCodeRequest()
            {
                Id             = id,
                New_LadingCode = lading_code,
            };

            return(View(request));
        }
Пример #2
0
        public async Task <IActionResult> UpdateLadingCode([FromBody] UpdateLadingCodeRequest request)
        {
            var result = await _transportService.UpdateLadingCode(request);

            if (!result.IsSuccess)
            {
                return(BadRequest(result));
            }
            return(Ok(result));
        }
Пример #3
0
        public async Task <IActionResult> UpdateLadingCode(UpdateLadingCodeRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(View(request));
            }
            var result = await _transportApiClient.UpdateLadingCode(request);

            if (result.IsSuccess)
            {
                TempData["result"] = "Cập nhật mã vận đơn thành công";
                return(RedirectToAction("Detail", "Transport", new { id = request.Id }));
            }
            ModelState.AddModelError("", result.Message);
            return(View(request));
        }
Пример #4
0
        public async Task <ApiResult <bool> > UpdateLadingCode(UpdateLadingCodeRequest 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 respone = await client.PutAsync($"/api/transport/newladingcode", httpContent);

            var result = await respone.Content.ReadAsStringAsync();

            if (respone.IsSuccessStatusCode)
            {
                return(JsonConvert.DeserializeObject <ApiSuccessResult <bool> >(result));
            }
            else
            {
                return(JsonConvert.DeserializeObject <ApiErrorResult <bool> >(result));
            }
        }
Пример #5
0
        public async Task <ApiResult <bool> > UpdateLadingCode(UpdateLadingCodeRequest request)
        {
            try
            {
                var result = await _context.Transports.Where(x => x.id == request.Id).FirstOrDefaultAsync();

                if (result != null)
                {
                    result.lading_code = request.New_LadingCode;
                    result.update_at   = DateTime.Now;
                    await _context.SaveChangesAsync();

                    return(new ApiSuccessResult <bool>());
                }
                else
                {
                    return(new ApiErrorResult <bool>("Không tìm thấy đơn vận chuyển" + request.Id));
                }
            }
            catch
            {
                return(new ApiErrorResult <bool>("Thêm mã vận đơn mới thất bại, hãy thử lại sau."));
            }
        }