public HttpResponseMessage updateStockTransferItem(String id, Models.TrnStockTransferItem stockTransferItem)
        {
            try
            {
                var stockTransferItems = from d in db.TrnStockTransferItems where d.Id == Convert.ToInt32(id) select d;
                if (stockTransferItems.Any())
                {
                    var updateStockTransferItem = stockTransferItems.FirstOrDefault();
                    updateStockTransferItem.STId            = stockTransferItem.STId;
                    updateStockTransferItem.ItemId          = stockTransferItem.ItemId;
                    updateStockTransferItem.ItemInventoryId = stockTransferItem.ItemInventoryId;
                    updateStockTransferItem.Particulars     = stockTransferItem.Particulars;
                    updateStockTransferItem.UnitId          = stockTransferItem.UnitId;
                    updateStockTransferItem.Quantity        = stockTransferItem.Quantity;
                    updateStockTransferItem.Cost            = stockTransferItem.Cost;
                    updateStockTransferItem.Amount          = stockTransferItem.Amount;

                    var item = from d in db.MstArticles where d.Id == stockTransferItem.ItemId select d;
                    updateStockTransferItem.BaseUnitId = item.First().UnitId;

                    var conversionUnit = from d in db.MstArticleUnits where d.ArticleId == stockTransferItem.ItemId && d.UnitId == stockTransferItem.UnitId select d;
                    if (conversionUnit.First().Multiplier > 0)
                    {
                        updateStockTransferItem.BaseQuantity = stockTransferItem.Quantity * (1 / conversionUnit.First().Multiplier);
                    }
                    else
                    {
                        updateStockTransferItem.BaseQuantity = stockTransferItem.Quantity * 1;
                    }

                    var baseQuantity = stockTransferItem.Quantity * (1 / conversionUnit.First().Multiplier);
                    if (baseQuantity > 0)
                    {
                        updateStockTransferItem.BaseCost = stockTransferItem.Amount / baseQuantity;
                    }
                    else
                    {
                        updateStockTransferItem.BaseCost = stockTransferItem.Amount;
                    }

                    db.SubmitChanges();

                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }
            }
            catch
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
        public Int32 insertStockTransferItem(Models.TrnStockTransferItem stockTransferItem)
        {
            try
            {
                Data.TrnStockTransferItem newStockTransferItem = new Data.TrnStockTransferItem();
                newStockTransferItem.STId            = stockTransferItem.STId;
                newStockTransferItem.ItemId          = stockTransferItem.ItemId;
                newStockTransferItem.ItemInventoryId = stockTransferItem.ItemInventoryId;
                newStockTransferItem.Particulars     = stockTransferItem.Particulars;
                newStockTransferItem.UnitId          = stockTransferItem.UnitId;
                newStockTransferItem.Quantity        = stockTransferItem.Quantity;
                newStockTransferItem.Cost            = stockTransferItem.Cost;
                newStockTransferItem.Amount          = stockTransferItem.Amount;
                newStockTransferItem.BaseUnitId      = stockTransferItem.BaseUnitId;

                var item = from d in db.MstArticles where d.Id == stockTransferItem.ItemId select d;
                newStockTransferItem.BaseUnitId = item.First().UnitId;

                var conversionUnit = from d in db.MstArticleUnits where d.ArticleId == stockTransferItem.ItemId && d.UnitId == stockTransferItem.UnitId select d;
                if (conversionUnit.First().Multiplier > 0)
                {
                    newStockTransferItem.BaseQuantity = stockTransferItem.Quantity * (1 / conversionUnit.First().Multiplier);
                }
                else
                {
                    newStockTransferItem.BaseQuantity = stockTransferItem.Quantity * 1;
                }

                var baseQuantity = stockTransferItem.Quantity * (1 / conversionUnit.First().Multiplier);
                if (baseQuantity > 0)
                {
                    newStockTransferItem.BaseCost = stockTransferItem.Amount / baseQuantity;
                }
                else
                {
                    newStockTransferItem.BaseCost = stockTransferItem.Amount;
                }

                db.TrnStockTransferItems.InsertOnSubmit(newStockTransferItem);
                db.SubmitChanges();

                return(newStockTransferItem.Id);
            }
            catch
            {
                return(0);
            }
        }