public async Task <IActionResult> PostSpecField([FromBody] AddSpecFieldToProductModel model, [FromServices] IProductSpecialFieldService productSpecialFieldService) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var productSpField = _mapper.Map <ProductSpecField>(model); productSpField = await productSpecialFieldService.Create(productSpField); var view = await productSpecialFieldService.SingleOrDefaultAsync(sp => _mapper.Map <ProductSpecFieldModel>(sp), sp => sp.Id == productSpField.Id, sp => sp.Include(d => d.SpecField)); return(Ok(view)); }
public async Task <IActionResult> PutSpecField([FromBody] UpdateProductSpecFieldModel model, [FromServices] IProductSpecialFieldService productSpecialFieldService) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var productSField = await productSpecialFieldService.GetByIdAsync(model.Id); if (productSField == null) { return(NotFound()); } productSField.Value = model.Value; productSField = await productSpecialFieldService.Update(productSField); var view = await productSpecialFieldService.SingleOrDefaultAsync(sp => _mapper.Map <ProductSpecFieldModel>(sp), sp => sp.Id == productSField.Id, sp => sp.Include(d => d.SpecField)); return(Ok(view)); }