Beispiel #1
0
        public ResResultModel SavePandianAsset(PdaPandianAssetFmModel model)
        {
            object userId = null;

            SecurityService.DoCheckLogin(model.AppKey, model.UserName, out userId);

            if (model == null)
            {
                return(ResResult.Response(false, "请求参数集为空字符串", ""));
            }
            var pandianId = Guid.Empty;

            if (model.PandianId == null || !Guid.TryParse(model.PandianId.ToString(), out pandianId))
            {
                return(ResResult.Response(false, "参数PandianId值为“" + model.PandianId + "”无效", ""));
            }
            if (model.ItemList == null || model.ItemList.Count == 0)
            {
                return(ResResult.Response(false, "请求参数集为空字符串", ""));
            }

            var pdaBll = new PandianAsset();
            var aisBll = new AssetInStore();
            var pdBll  = new Pandian();
            var effect = 0;

            foreach (var item in model.ItemList)
            {
                PandianAssetInfo pdaModel   = null;
                AssetInStoreInfo assetModel = null;

                var assetId = Guid.Empty;
                if (item.AssetId != null)
                {
                    Guid.TryParse(item.AssetId.ToString(), out assetId);
                }
                if (assetId == Guid.Empty)
                {
                    if (string.IsNullOrWhiteSpace(item.Barcode))
                    {
                        continue;
                    }

                    if (pdaBll.IsExist(item.Barcode))
                    {
                        assetModel = aisBll.GetModelByBarcode(item.Barcode);
                        if (assetModel != null)
                        {
                            CreateAssetInStoreInfo(item, ref assetModel, ref pdaModel);

                            pdaModel.AssetId   = assetModel.Id;
                            pdaModel.PandianId = pandianId;
                            assetModel.UserId  = Guid.Parse(userId.ToString());
                            pdaModel.UserId    = assetModel.UserId;
                            effect            += aisBll.Update(assetModel);
                            effect            += pdaBll.Update(pdaModel);
                        }
                    }
                    else
                    {
                        CreateAssetInStoreInfo(item, ref assetModel, ref pdaModel);
                        assetModel.Id      = Guid.NewGuid();
                        pdaModel.AssetId   = assetModel.Id;
                        pdaModel.PandianId = pandianId;
                        assetModel.UserId  = Guid.Parse(userId.ToString());
                        pdaModel.UserId    = assetModel.UserId;
                        effect            += aisBll.InsertByOutput(assetModel);
                        effect            += pdaBll.Insert(pdaModel);
                    }
                }
                else
                {
                    assetModel = aisBll.GetModel(assetId);
                    pdaModel   = pdaBll.GetModel(pandianId, assetId);
                    CreateAssetInStoreInfo(item, ref assetModel, ref pdaModel);

                    pdaModel.UserId = Guid.Parse(userId.ToString());
                    effect         += pdaBll.Update(pdaModel);
                }
            }

            if (effect < 1)
            {
                return(ResResult.Response(false, "操作失败", ""));
            }

            return(ResResult.Response(true, "调用成功", ""));
        }
Beispiel #2
0
        public ResResultModel SaveAssetInStore(AssetInStoreFmModel model)
        {
            try
            {
                if (model == null)
                {
                    return(ResResult.Response(false, "未获取到任何可保存的数据", ""));
                }

                var modelInfo = new AssetInStoreInfo();

                Guid gId = Guid.Empty;
                if (model.CategoryId != null)
                {
                    Guid.TryParse(model.CategoryId.ToString(), out gId);
                }
                modelInfo.CategoryId = gId;
                if (model.UseCompanyId != null)
                {
                    Guid.TryParse(model.UseCompanyId.ToString(), out gId);
                }
                modelInfo.UseCompanyId = gId;
                if (model.UseDepmtId != null)
                {
                    Guid.TryParse(model.UseDepmtId.ToString(), out gId);
                }
                modelInfo.UseDepmtId = gId;
                if (model.RegionId != null)
                {
                    Guid.TryParse(model.RegionId.ToString(), out gId);
                }
                modelInfo.RegionId = gId;
                if (model.OwnedCompanyId != null)
                {
                    Guid.TryParse(model.OwnedCompanyId.ToString(), out gId);
                }
                modelInfo.OwnedCompanyId = gId;
                if (model.PictureId != null)
                {
                    Guid.TryParse(model.PictureId.ToString(), out gId);
                }
                modelInfo.PictureId = gId;

                DateTime time = DateTime.MinValue;
                DateTime.TryParse(model.SBuyDate, out time);

                modelInfo.Barcode         = model.Barcode;
                modelInfo.Named           = model.Named;
                modelInfo.SpecModel       = model.SpecModel;
                modelInfo.SNCode          = model.SNCode;
                modelInfo.Unit            = model.Unit;
                modelInfo.Price           = model.Price;
                modelInfo.BuyDate         = time == DateTime.MinValue ? DateTime.Parse("1754-01-01") : time;
                modelInfo.UsePerson       = model.UsePerson;
                modelInfo.Manager         = model.Manager;
                modelInfo.StoreLocation   = model.StoreLocation;
                modelInfo.UseExpireMonth  = model.UseExpireMonth;
                modelInfo.Supplier        = model.Supplier;
                modelInfo.Remark          = model.Remark;
                modelInfo.LastUpdatedDate = DateTime.Now;
                modelInfo.UserId          = Guid.Parse(SecurityService.GetUserId().ToString());

                if (model.Id != null)
                {
                    Guid.TryParse(model.Id.ToString(), out gId);
                }
                modelInfo.Id = gId;

                var bll    = new AssetInStore();
                int effect = -1;

                if (modelInfo.Id.Equals(Guid.Empty))
                {
                    effect = bll.Insert(modelInfo);
                }
                else
                {
                    effect = bll.Update(modelInfo);
                }
                if (effect < 1)
                {
                    return(ResResult.Response(false, "操作失败,数据库操作异常,请稍后再重试", ""));
                }

                return(ResResult.Response(true, "操作成功", ""));
            }
            catch (Exception ex)
            {
                return(ResResult.Response(false, "操作异常:" + ex.Message + "", ""));
            }
        }