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 JsonResult ClaimCompensation(SaleCompensationInfoItem model) { if (model == null || model.SaleProductItemId.HasValue == false) { ModelState.AddModelError(string.Empty, "找不到请求索赔所对应的货品。"); return(Json(this.GetModelStateErrors(ModelState))); } SaleClaimCompensation entity = this.GetSaleProductCompensationItem(model); string errorMsg = AppBusinessManager.Instance.AddOrUpdateSaleClaimCompensation( HttpContext.GetOwinContext(), db, entity, model); if (!string.IsNullOrEmpty(errorMsg)) { ModelState.AddModelError(string.Empty, errorMsg); } return(Json(this.GetModelStateErrors(ModelState))); //FIXED 销售索赔业务逻辑 //return View(this.GetModelStateErrors(ModelState)); }