public async Task <ApiResult <int> > Create(CreateProductTypeGroup bundle) { var productTypeGroup = _mapper.Map <ProductTypeGroup>(bundle); var code = await _context.ManageCodes.FirstOrDefaultAsync(x => x.Name == bundle.Code); var stt = 1; Location: var location = code.Location + stt; var str = code.Name + location; var checkCode = await _context.ProductTypeGroups.AnyAsync(x => x.Code == str); if (checkCode) { stt++; goto Location; } code.Location = location; _context.ManageCodes.Update(code); await _context.SaveChangesAsync(); productTypeGroup.Code = str; _context.ProductTypeGroups.Add(productTypeGroup); await _context.SaveChangesAsync(); // số bản ghi nếu return return(new ApiSuccessResult <int>(productTypeGroup.Id)); }
public async Task <ApiResult <GetByIdListProductTypeGroup> > Create(CreateProductTypeGroup bundle) { var json = JsonConvert.SerializeObject(bundle); var httpContent = new StringContent(json, Encoding.UTF8, "application/json"); var url = $"/api/ProductTypeGroup"; var result = await Create <GetByIdListProductTypeGroup>(url, httpContent); return(result); }
public async Task <IActionResult> Create([FromBody] CreateProductTypeGroup request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var resultId = await _productTypeGroupService.Create(request); if (!resultId.IsSuccessed) { return(BadRequest(resultId)); } var result = await _productTypeGroupService.GetById(resultId.ResultObj); return(Ok(result)); }
public async Task <ApiResult <GetByIdListProductTypeGroup> > Create(CreateProductTypeGroup bundle) { var result = await _productTypeGroupApiClient.Create(bundle); return(result); }