Пример #1
0
        public StoreInModel(StoreIn storeIn)
            : base(storeIn)
        {
            if (storeIn.Supplier != null)
            {
                this.SupplierId = storeIn.Supplier.Id;
                this.SupplierName = storeIn.Supplier.Name;
            }

            if (storeIn.Buyer != null)
            {
                this.BuyerId = storeIn.Buyer.Id;
                this.BuyerName = storeIn.Buyer.LoginName;
            }

            if (storeIn.StoreInType != null)
            {
                this.StoreInTypeId = storeIn.StoreInType.Id;
                this.StoreInTypeName = storeIn.StoreInType.Name;
            }

            this.AmountPay = storeIn.AmountPay;
        }
Пример #2
0
 public static StoreInModel From(StoreIn storeIn)
 {
     return new StoreInModel(storeIn);
 }
Пример #3
0
        public ActionResult SaveOrUpdate(StoreIn obj, string sgoods)
        {
            try
            {
                if (obj.Id > 0)
                {
                    obj = this.StoreInRepository.Get(obj.Id);
                    TryUpdateModel(obj);

                    var jser = new JavaScriptSerializer();
                    IList<StoreInDetailModel> datas = jser.Deserialize<IList<StoreInDetailModel>>(sgoods);

                    var list = this.StoreInDetailRepository.GetAll(new StoreInDetailQuery
                    {
                        StoreInId = obj.Id
                    });

                    IList<StoreInDetail> dts = new List<StoreInDetail>();

                    //找到存在的进行更新,不存在的删除
                    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.StoreInDetailRepository.Delete(item1);
                        }
                    }

                    //添加新增的
                    foreach (var item in datas)
                    {
                        dts.Add(new StoreInDetail()
                        {
                            StoreIn = 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.StoreInDetailRepository.SaveOrUpdate(item);
                    }
                }
                else
                {
                    if (obj.Store == null)
                    {
                        return JsonError("请选择仓库");
                    }

                    if (obj.Supplier == null)
                    {
                        return JsonError("请选择供应商");
                    }

                    if (obj.Buyer == null)
                    {
                        return JsonError("请选择采购员");
                    }
                }

                obj = this.StoreInRepository.SaveOrUpdate(obj);

                return JsonSuccess(obj);
            }
            catch (Exception ex)
            {
                return JsonError(ex.Message);
            }
        }