public IHttpActionResult PostAddCharacteristicToProduct([FromBody] ProductCharacteristicEditModel model)
        {
            var product = db.Products.Include("ProductCategory.Characteristics")
                          .FirstOrDefault(it => it.ProductId == model.ProductId);

            if (product == null)
            {
                return(Ok("No such product exisits"));
            }

            var characteristic = product.ProductCategory.Characteristics
                                 .FirstOrDefault(it => it.CharacteristicId == model.CharacteristicId);

            if (characteristic == null)
            {
                return(Ok("No such characteristic exisits"));
            }

            var productCharacteristic = new BB.Core.Model.ProductCharacteristic();

            productCharacteristic.Product        = product;
            productCharacteristic.Characteristic = characteristic;
            productCharacteristic.Value          = model.Value;
            db.ProductCharacteristics.Add(productCharacteristic);
            db.SaveChanges();

            return(Ok(new { characteristic = productCharacteristic.ConvertToDTO() }));
        }
Exemplo n.º 2
0
 public static ProductCharacteristic ConvertToDTO(this BB.Core.Model.ProductCharacteristic entity)
 {
     return(new ProductCharacteristic()
     {
         CharacteristicName = entity.Characteristic.Name,
         CharacteristicId = entity.CharacteristicId,
         Value = entity.Value,
         ProductId = entity.ProductId
     });
 }