Пример #1
0
        /// <summary>
        /// 删除平台商品
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task DeleteAsync(PlatformCommodityDto dto, CancellationToken token = default)
        {
            using (var db = new GuoGuoCommunityContext())
            {
                if (!Guid.TryParse(dto.Id, out var ID))
                {
                    throw new NotImplementedException("平台商品ID无效!");
                }
                var platformCommoditie = await db.PlatformCommodities.Where(item => item.Id == ID && item.IsDeleted == false).FirstOrDefaultAsync(token);

                if (platformCommoditie == null)
                {
                    throw new NotImplementedException("该平台商品不存在!");
                }
                platformCommoditie.LastOperationTime   = dto.OperationTime;
                platformCommoditie.LastOperationUserId = dto.OperationUserId;
                platformCommoditie.DeletedTime         = dto.OperationTime;
                platformCommoditie.IsDeleted           = true;
                int result = await db.SaveChangesAsync(token);

                if (result <= 0)
                {
                    throw new NotImplementedException("数据执行失败。");
                }
            }
        }
Пример #2
0
        public async Task <PlatformCommodity> AddAsync(PlatformCommodityDto dto, CancellationToken token = default)
        {
            using (var db = new GuoGuoCommunityContext())
            {
                var platformCommodity = await db.PlatformCommodities.Where(x => x.BarCode == dto.BarCode && x.IsDeleted == false).FirstOrDefaultAsync(token);

                if (platformCommodity != null)
                {
                    throw new NotImplementedException("该商品信息已存在!");
                }
                var entity = db.PlatformCommodities.Add(new PlatformCommodity
                {
                    Name                  = dto.Name,
                    BarCode               = dto.BarCode,
                    ImageUrl              = dto.ImageUrl,
                    Price                 = dto.Price,
                    CreateOperationTime   = dto.OperationTime,
                    CreateOperationUserId = dto.OperationUserId,
                    LastOperationTime     = dto.OperationTime,
                    LastOperationUserId   = dto.OperationUserId
                });
                await db.SaveChangesAsync(token);

                return(entity);
            }
        }
Пример #3
0
        /// <summary>
        /// 更新平台商品
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task UpdateAsync(PlatformCommodityDto dto, CancellationToken token = default)
        {
            using (var db = new GuoGuoCommunityContext())
            {
                if (!Guid.TryParse(dto.Id, out var ID))
                {
                    throw new NotImplementedException("平台商品ID无效!");
                }
                var model = await db.PlatformCommodities.Where(item => item.Id == ID).FirstOrDefaultAsync(token);

                if (model == null)
                {
                    throw new NotImplementedException("平台商品不存在!");
                }
                if (db.PlatformCommodities.Any(item => item.BarCode == dto.BarCode && item.IsDeleted == false && item.Id != ID))
                {
                    throw new NotImplementedException("当前条码已经存在!");
                }
                model.Name                = dto.Name;
                model.Price               = dto.Price;
                model.ImageUrl            = dto.ImageUrl;
                model.LastOperationTime   = dto.OperationTime;
                model.LastOperationUserId = dto.OperationUserId;
                if (await db.SaveChangesAsync(token) <= 0)
                {
                    throw new NotImplementedException("数据执行失败。");
                }
            }
        }
Пример #4
0
        /// <summary>
        /// 查询所有平台商品
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task <PlatformCommodityForPage> GetListForPageAsync(PlatformCommodityDto dto, CancellationToken token = default)
        {
            using (var db = new GuoGuoCommunityContext())
            {
                var list = db.PlatformCommodities.Where(item => item.IsDeleted == false);
                if (!string.IsNullOrEmpty(dto.Name))
                {
                    list = list.Where(item => item.Name.Contains(dto.Name));
                }
                if (!string.IsNullOrEmpty(dto.BarCode))
                {
                    list = list.Where(item => item.BarCode == dto.BarCode);
                }
                list = list.OrderByDescending(item => item.CreateOperationTime);
                List <PlatformCommodity> resultList = await list.Skip((dto.PageIndex - 1) *dto.PageSize).Take(dto.PageSize).ToListAsync(token);

                PlatformCommodityForPage pagelist = new PlatformCommodityForPage {
                    PlatformCommoditieForPageList = resultList, Count = list.Count()
                };
                return(pagelist);
            }
        }
        public async Task <ApiResult <AddBuildingOutput> > Add([FromBody] AddPlatformCommodityInput input, CancellationToken cancelToken)
        {
            if (Authorization == null)
            {
                return(new ApiResult <AddBuildingOutput>(APIResultCode.Unknown, new AddBuildingOutput {
                }, APIResultMessage.TokenNull));
            }
            if (string.IsNullOrWhiteSpace(input.Name))
            {
                throw new NotImplementedException("商品名称信息为空!");
            }
            if (string.IsNullOrWhiteSpace(input.BarCode))
            {
                throw new NotImplementedException("商品条形码信息为空!");
            }

            var user = _tokenRepository.GetUser(Authorization);

            if (user == null)
            {
                return(new ApiResult <AddBuildingOutput>(APIResultCode.Unknown, new AddBuildingOutput {
                }, APIResultMessage.TokenError));
            }
            var dto = new PlatformCommodityDto
            {
                Name            = input.Name,
                Price           = input.Price,
                BarCode         = input.BarCode,
                OperationTime   = DateTimeOffset.Now,
                ImageUrl        = input.ImageUrl,
                OperationUserId = user.Id.ToString()
            };

            var entity = await _platformCommodityRepository.AddAsync(dto, cancelToken);

            return(new ApiResult <AddBuildingOutput>(APIResultCode.Success, new AddBuildingOutput {
                Id = entity.Id.ToString()
            }));
        }
Пример #6
0
 public Task <List <PlatformCommodity> > GetAllAsync(PlatformCommodityDto dto, CancellationToken token = default)
 {
     throw new NotImplementedException();
 }
        public async Task <ApiResult <GetForBarCodePlatformCommodityOutput> > GetForBarCode([FromUri] string barCode, CancellationToken cancelToken)
        {
            if (Authorization == null)
            {
                return(new ApiResult <GetForBarCodePlatformCommodityOutput>(APIResultCode.Unknown, new GetForBarCodePlatformCommodityOutput {
                }, APIResultMessage.TokenNull));
            }
            var user = _tokenRepository.GetUser(Authorization);

            if (user == null)
            {
                return(new ApiResult <GetForBarCodePlatformCommodityOutput>(APIResultCode.Unknown, new GetForBarCodePlatformCommodityOutput {
                }, APIResultMessage.TokenError));
            }
            if (string.IsNullOrWhiteSpace(barCode))
            {
                throw new NotImplementedException("条形码为空!");
            }

            // ALiYunQueryBarCode.Query("6902083881405");

            var data = await _platformCommodityRepository.GetForBarCodeAsync(barCode, cancelToken);

            if (data == null)
            {
                var barQueryModel = ALiYunQueryBarCode.Query(barCode);
                if (!string.IsNullOrWhiteSpace(barQueryModel.GoodsName))
                {
                    var url = "";
                    if (!string.IsNullOrWhiteSpace(barQueryModel.Img))
                    {
                        var aa = SaveImageFromWebUtility.SaveImageFromWeb(barQueryModel.Img, HttpContext.Current.Server.MapPath("~/Upload/PlatformCommodityCertification/"), DateTime.Now.ToString("yyyyMMddhhmmssffffff"));
                        url = "/PlatformCommodityCertification/" + aa;
                    }

                    var dto = new PlatformCommodityDto
                    {
                        Name            = barQueryModel.GoodsName,
                        Price           = Convert.ToDecimal(barQueryModel.Price),
                        BarCode         = barCode,
                        OperationTime   = DateTimeOffset.Now,
                        ImageUrl        = url,
                        OperationUserId = user.Id.ToString()
                    };

                    var entity = await _platformCommodityRepository.AddAsync(dto, cancelToken);

                    return(new ApiResult <GetForBarCodePlatformCommodityOutput>(APIResultCode.Success, new GetForBarCodePlatformCommodityOutput
                    {
                        Id = entity.Id.ToString(),
                        Name = barQueryModel.GoodsName,
                        BarCode = barCode,
                        ImageUrl = entity.ImageUrl,
                        Price = entity.Price
                    }));
                }
                return(new ApiResult <GetForBarCodePlatformCommodityOutput>(APIResultCode.Success, new GetForBarCodePlatformCommodityOutput {
                }));
            }
            return(new ApiResult <GetForBarCodePlatformCommodityOutput>(APIResultCode.Success, new GetForBarCodePlatformCommodityOutput
            {
                Id = data.Id.ToString(),
                Name = data.Name,
                BarCode = data.BarCode,
                ImageUrl = data.ImageUrl,
                Price = data.Price
            }));
        }