Esempio n. 1
0
 public IHttpActionResult PostInventoryItem([FromBody] ApiInventoryItem inventoryItem)
 {
     try
     {
         if (inventoryItem != null && ModelState.IsValid)
         {
             EntityMapper <ApiInventoryItem, InventoryItem> mapObj = new EntityMapper <ApiInventoryItem, InventoryItem>();
             InventoryItem itemObj = new InventoryItem();
             itemObj = mapObj.Translate(inventoryItem);
             _itemService.SaveInventoryItem(itemObj);
             return(CreatedAtRoute("DefaultApi", new { id = inventoryItem.ID }, inventoryItem));
         }
         else
         {
             var message = inventoryItem == null ? "Invalid Request" : (string.Join(" | ", ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage)) + string.Join(" | ", ModelState.Values.SelectMany(v => v.Errors).Select(e => e.Exception)));
             //return BadRequest(message);
             return(Content(HttpStatusCode.BadRequest, message));
         }
     }
     catch (System.Exception)
     {
         return(InternalServerError());
     }
 }