public StoreOutModel(StoreOut storeOut) : base(storeOut) { if (storeOut.Customer != null) { this.CustomerId = storeOut.Customer.Id; this.CustomerName = storeOut.Customer.Name; } if (storeOut.Seller != null) { this.SellerId = storeOut.Seller.Id; this.SellerName = storeOut.Seller.LoginName; } if (storeOut.StoreOutType != null) { this.StoreOutTypeId = storeOut.StoreOutType.Id; this.StoreOutTypeName = storeOut.StoreOutType.Name; } this.AmountReceipt = storeOut.AmountReceipt; }
public ActionResult SaveOrUpdate(StoreOut obj, string sgoods) { try { if (obj.Id > 0) { obj = this.StoreOutRepository.Get(obj.Id); TryUpdateModel(obj); var jser = new JavaScriptSerializer(); IList <StoreOutDetailModel> datas = jser.Deserialize <IList <StoreOutDetailModel> >(sgoods); var list = this.StoreOutDetailRepository.GetAll(new StoreOutDetailQuery { StoreOutId = obj.Id }); IList <StoreOutDetail> dts = new List <StoreOutDetail>(); //找到存在的进行更新,不存在的删除 foreach (var item1 in list) { bool bFlag = false; for (int i = datas.Count - 1; i >= 0; i--) { var item2 = datas[i]; if (item1.Goods.Id == item2.Id) { item1.Price = item2.Price; item1.Quantity = item2.StoreGoodsQuantity; item1.TotalAomount = item2.TotalAomount; item1.Note = item2.StoreGoodsNote; dts.Add(item1); datas.Remove(item2); bFlag = true; } } if (!bFlag) { this.StoreOutDetailRepository.Delete(item1); } } //添加新增的 foreach (var item in datas) { dts.Add(new StoreOutDetail() { StoreOut = obj, Goods = this.GoodsRepository.Get(item.Id), Price = item.Price, Quantity = item.StoreGoodsQuantity, TotalAomount = item.TotalAomount, Note = item.StoreGoodsNote }); } foreach (var item in dts) { this.StoreOutDetailRepository.SaveOrUpdate(item); } } else { if (obj.Store == null) { return(JsonError("请选择仓库")); } if (obj.Customer == null) { return(JsonError("请选择客户")); } if (obj.Seller == null) { return(JsonError("请选择销售员")); } } obj = this.StoreOutRepository.SaveOrUpdate(obj); return(JsonSuccess(obj)); } catch (Exception ex) { return(JsonError(ex.Message)); } }
public ActionResult Detail(int id) { StoreOut item = this.StoreOutRepository.Get(id); return(View(item)); }
public static StoreOutModel From(StoreOut storeOut) { return(new StoreOutModel(storeOut)); }