public async Task <ApiResult <bool> > UpdatePack(long id, UpdateMaterialPack bundle) { var json = JsonConvert.SerializeObject(bundle); var httpContent = new StringContent(json, Encoding.UTF8, "application/json"); var url = $"/api/Material/pack/" + $"{id}"; var result = await Update <bool>(url, httpContent); return(result); }
public async Task <IActionResult> Update(long id, [FromBody] UpdateMaterialPack request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await _materialService.UpdatePack(request); if (!result.IsSuccessed) { return(BadRequest(result)); } return(Ok(result)); }
public async Task <ApiResult <bool> > UpdatePack(UpdateMaterialPack bundle) { var pack = await _context.Packs.FindAsync(bundle.Id); if (pack == null) { return(new ApiErrorResult <bool>("Đóng gói không tồn tại")); } if (bundle.Default) { pack.Default = true; pack.Name = bundle.Name; } else { var count = await _context.Packs .Where(x => x.IdMaterials == bundle.IdMaterial && x.Id != bundle.Id) .AnyAsync(c => EF.Functions.Collate(c.Name.ToUpper().Trim(), SystemConstants.Collate_AS) == bundle.Name.ToUpper().Trim()); if (!count) { pack.Default = false; pack.Name = bundle.Name; pack.Value = bundle.Value; } else { return(new ApiErrorResult <bool>("Tên đóng gói đã tồn tại")); } } _context.Packs.Update(pack); await _context.SaveChangesAsync(); return(new ApiSuccessResult <bool>()); }
public async Task <ApiResult <bool> > UpdatePack(UpdateMaterialPack bundle) { var data = await _materialApiClient.UpdatePack(bundle.Id, bundle); return(data); }