public JsonResult Insert(StoreProductCollocation collocationInfo)
        {
            try
            {
                string guid = Guid.NewGuid().ToString().Replace("-", "");
                collocationInfo.Guid      = guid;
                collocationInfo.IsDeleted = false;
                collocationInfo.IsEnabled = true;
                HttpFileCollectionBase files = Request.Files;
                OperationResult        oper  = new OperationResult(OperationResultType.Error);

                if (files.Count == 0)
                {
                    oper.Message = "请选择图片";
                    return(Json(oper));
                }
                else
                {
                    string   conPath  = "/Content/UploadFiles/StoreCollocation";
                    DateTime now      = DateTime.Now;
                    Guid     gid      = Guid.NewGuid();
                    string   fileName = gid.ToString();
                    conPath = conPath + now.Year.ToString() + "/" + now.Month.ToString() + "/" + now.Day.ToString() + "/" + now.Hour.ToString() + "/" + now.ToString("yyyyMMddHHmmss") + ".jpg";
                    files[0].SaveAs(FileHelper.UrlToPath(conPath));
                    collocationInfo.ThumbnailPath = conPath;
                    OperationResult rs = _storeProductCollocationContract.Insert(collocationInfo);
                    return(Json(rs));
                }
            }
            catch (Exception e)
            {
                return(Json(new OperationResult(OperationResultType.Error, "获取失败!", e.Message)));
            }
        }
Example #2
0
        //校验店铺搭配是否存在
        private Tuple <bool, string> CheckCollcationEntity(StoreProductCollocation entity)
        {
            if (entity == null)
            {
                return(Tuple.Create(false, "搭配不存在"));
            }


            if (entity.IsDeleted)
            {
                return(Tuple.Create(false, "搭配已经被删除"));
            }
            if (!entity.IsEnabled)
            {
                return(Tuple.Create(false, "搭配被禁用"));
            }
            return(Tuple.Create(true, string.Empty));
        }
Example #3
0
        private OperationResult BatchAddCollocationItem(StoreProductCollocation orderblankEntity, List <StoreCollocationInfo> inventoryList, params Product_Model[] models)
        {
            var barcodes = models.Select(m => m.ProductBarcode).ToList();
            var orderblankItemsFromDb = orderblankEntity.StoreCollocationInfoItems.ToList();
            var barcodseFromDb        = orderblankItemsFromDb.Select(x => x.ProductBarcode).ToList();
            var errorCodes            = barcodseFromDb.Intersect(barcodes);

            if (errorCodes.Any())
            {
                return(new OperationResult(OperationResultType.Error, "存在已添加的条码" + string.Join(",", errorCodes)));
            }
            List <StoreCollocationInfo> sci = new List <StoreCollocationInfo>();

            foreach (var groupItem in models)
            {
                var itemEntity = orderblankItemsFromDb.FirstOrDefault(i => i.StoreCollocationId == groupItem.ProductId &&
                                                                      i.ProductOrigNumberId == groupItem.Id
                                                                      );
                if (itemEntity == null)
                {
                    //新增
                    var entity = new StoreCollocationInfo()
                    {
                        StoreCollocationId  = groupItem.ProductId, //OrderblankId = orderblankEntity.Id,
                        ProductOrigNumberId = groupItem.Id,
                        ProductBarcode      = groupItem.ProductNumber,

                        OperatorId = AuthorityHelper.OperatorId
                    };
                    sci.Add(entity);
                }
            }

            //删除原有
            //_storeCollocationInfoContract.DeleteByCollocationId(orderblankEntity.Id);
            //添加
            return(_storeCollocationInfoContract.Insert(sci.ToArray()));
        }