public async Task <ActionResult> Post(product_property productProperty) { if (ModelState.IsValid) { string proplem = ConstraintsTest(productProperty).Result; if (proplem == "") { var result = await dbContext.fdc_products_properties.AddAsync(productProperty); if (result != null && result.State == EntityState.Added) { try { await dbContext.SaveChangesAsync(); var response = await dbContext.GetProductsProperties(result.Entity.product_property_id); return(Ok(response)); } catch { } } return(NotFound($"{result.State}")); } else { return(NotFound($"{proplem}")); } } return(BadRequest()); }
public async Task <ActionResult> Put(int id, product_property productProperty) { if (ModelState.IsValid) { productProperty.product_property_id = id; string proplem = ConstraintsTest(productProperty).Result; if (proplem == "") { var result = dbContext.fdc_products_properties.Update(productProperty); if (result != null && result.State == EntityState.Modified) { await dbContext.SaveChangesAsync(); var response = await dbContext.GetProductsProperties(result.Entity.product_property_id); return(Ok(response)); } return(NotFound("Свойства продукта не найден")); } else { return(NotFound($"{proplem}")); } } return(BadRequest()); }
/// <summary> /// Проверка на существования связанных сущностей в БД /// </summary> private async Task <string> ConstraintsTest(product_property productProperty) { var product_type = await dbContext.GetProductType(productProperty.product_type_id); var okei = await dbContext.GetOKEI(productProperty.okei_id); string proplem = string.Format("{0}{1}" , product_type == null ? "Не указан тип продукта. " : "" , okei == null ? "Не указаны Единицы измерения " : ""); return(proplem); }