public async Task <HttpResponseMessage> AddDocument()
        {
            var httpRequest = HttpContext.Current.Request;

            // Step 1: Extract form data received from frontend
            var itemData = System.Convert.ToString(httpRequest.Form[Constants.FormName]).Trim();

            // Step 2: Map form-data to the stored procedure object
            spInsertItem = Newtonsoft.Json.JsonConvert.DeserializeObject <SpInsertItem>(itemData);

            // Step 3: Map additional data required for file upload if user selects file
            if (string.IsNullOrEmpty(spInsertItem.FileName) && httpRequest.Files.Count > 0)
            {
                var file = httpRequest.Files[0];

                spInsertItem.FileName      = Path.GetFileNameWithoutExtension(file.FileName);
                spInsertItem.FileExtension = Path.GetExtension(file.FileName);
            }

            // Step 4: Insert item
            var itemID = await itemManager.AddItem(spInsertItem);

            // Step 5: If item is inserted and item has file then upload it to defined directory
            if (httpRequest.Files.Count > 0 && itemID > 0)
            {
                await itemManager.UploadImage(httpRequest.Files[0], itemID);
            }

            // Step 6: Construct response object
            if (itemID > 0)
            {
                responseMessage = Request.CreateResponse(HttpStatusCode.OK, new { Message = "Item added successfullly!" });
            }
            else
            {
                responseMessage = Request.CreateResponse(HttpStatusCode.OK, new { Message = "Something went wrong" });
            }

            return(responseMessage);
        }
 /// <summary>
 /// Add item to DB
 /// </summary>
 /// <param name="spInsertItem"></param>
 /// <returns></returns>
 public async Task <int> AddItem(IspInsertItem spInsertItem)
 {
     return(await _databaseManager.AddRecord(StoredProcedure.spInsertItem, spInsertItem));
 }
 public ItemController()
 {
     itemManager  = DIUnity.GetUnityContainer().Resolve <IItemManager>();
     spInsertItem = DIUnity.GetUnityContainer().Resolve <IspInsertItem>();
 }