public string AddOrUpdateSaleClaimCompensation(IOwinContext owinContext,
                                                       ExtendedIdentityDbContext db, SaleClaimCompensation model, SaleCompensationInfoItem viewModel)
        {
            try
            {
                if (model == null)
                {//新建索赔
                    model = db.SaleClaimCompensations.Create();
                    if (viewModel.SaleProductItemId.HasValue)
                    {
                        var saleItem = db.SaleProductItems.Find(viewModel.SaleProductItemId.Value);

                        if (saleItem != null)
                        {
                            saleItem.SaleContract.ClaimCompensation = model;
                            db.SaleClaimCompensations.Add(model);
                        }
                    }
                }

                if (model != null)
                {
                    var compItem = db.SaleClaimCompensationItems.FirstOrDefault(
                        m => m.SaleProductItemId == viewModel.SaleProductItemId.Value);
                    if (compItem == null)
                    {
                        compItem = db.SaleClaimCompensationItems.Create();
                        model.SaleClaimCompensationItems.Add(compItem);
                        db.SaleClaimCompensationItems.Add(compItem);
                    }
                    compItem.SaleProductItemId  = viewModel.SaleProductItemId.Value;
                    compItem.CompensationReason = viewModel.CompensationReason;
                    compItem.Compensation       = viewModel.Compensation.GetValueOrDefault();
                }

                int rec = db.SaveChanges();
                if (rec < 1)
                {
                    return("销售索赔失败。");
                }
            }
            catch (Exception e)
            {
                string errorMsg = "销售索赔失败。" + e.Message;
                LogHelper.Error(errorMsg, e);
                if ((e is AggregateException) && (e as AggregateException).InnerException != null)
                {
                    LogHelper.Error(errorMsg, (e as AggregateException).InnerException);
                    errorMsg += "\t\t" + (e as AggregateException).InnerException.Message;
                }
                return(errorMsg);
            }
            return(string.Empty);
        }
        public string AddOrUpdateStockItem(ExtendedIdentityDbContext db,
                                           StockItem model, string userName)
        {
            try
            {
                ProductItem productItem = db.ProductItems.Find(model.ProductItemId);
                StockItem   item        = db.StockItems.Create();
                item.ProductItem           = productItem;               // model.ProductItem;
                item.ProductItemId         = productItem.ProductItemId; // model.ProductItemId;
                item.Quantity              = model.Quantity;
                item.StockInDate           = DateTime.Now;
                item.StockStatus           = model.StockStatus;// StockStatus.InStock;
                item.StockWeight           = model.StockWeight;
                item.StoreHouse            = model.StoreHouse;
                item.StoreHouseId          = model.StoreHouseId;
                item.StoreHouseMountNumber = model.StoreHouseMountNumber;
                item.IsAllSold             = model.IsAllSold;
                //if (productItem.Quantity <= item.Quantity)
                //{
                //    productItem.Status = ProductItemStatus.Received;
                //    productItem.ReceiveTime = DateTime.Now;
                //}
                db.StockItems.Add(item);
                db.SaveChanges();

                return(string.Empty);
            }
            catch (Exception e)
            {
                string errorMsg = e.Message;
                if ((e is AggregateException) &&
                    (e as AggregateException).InnerException != null)
                {
                    errorMsg = string.Format(errorMsg + "\t\t{0}",
                                             (e as AggregateException).InnerException.Message);
                    LogHelper.Error(errorMsg, e.InnerException);
                }
                LogHelper.Error(errorMsg, e);
                return(errorMsg);
            }
        }
 public string AddOrUpdateSaleProductItem(IOwinContext owinContext,
                                          ExtendedIdentityDbContext db, SaleProductItem item)
 {
     try
     {
         int rec = db.SaveChanges();
         if (rec < 1)
         {
             return("销售货品状态信息更新失败。");
         }
     }
     catch (Exception e)
     {
         string errorMsg = "销售货品状态信息更新失败。" + e.Message;
         LogHelper.Error(errorMsg, e);
         if ((e is AggregateException) && (e as AggregateException).InnerException != null)
         {
             LogHelper.Error(errorMsg, (e as AggregateException).InnerException);
             errorMsg += "\t\t" + (e as AggregateException).InnerException.Message;
         }
         return(errorMsg);
     }
     return(string.Empty);
 }