Beispiel #1
0
        /// <summary>
        /// 添加店铺信息信息
        /// </summary>
        /// <param name="inputDtos">要添加的店铺信息DTO信息</param>
        /// <returns>业务操作结果</returns>
        public OperationResult AddGoodsComments(params GoodsCommentInputDto[] inputDtos)
        {
            OperationResult result = GoodsCommentRepository.Insert(inputDtos,
                                                                   dto =>
            {
            },
                                                                   (dto, entity) =>
            {
                if (dto.GoodsId.HasValue && dto.GoodsId.Value > 0)
                {
                    Goods.Models.Goods goods = GoodsRepository.GetByKey(dto.GoodsId.Value);
                    if (goods == null)
                    {
                        throw new Exception("商品不存在");
                    }
                    goods.GoodsComments.Add(entity);
                    entity.Goods = goods;
                }

                if (dto.UserId.HasValue && dto.UserId.Value > 0)
                {
                    Identity.Models.User user = UserRepository.GetByKey(dto.UserId.Value);
                    if (user == null)
                    {
                        throw new Exception("用户不存在");
                    }
                    entity.User = user;
                }

                return(entity);
            });

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// 添加信息信息
        /// </summary>
        /// <param name="inputDtos">要添加的店铺信息DTO信息</param>
        /// <returns>业务操作结果</returns>
        public async Task <OperationResult> AddCartGoodses(params CartGoodsInputDto[] inputDtos)
        {
            CartGoodsRepository.UnitOfWork.TransactionEnabled = true;
            List <string> names = new List <string>();

            foreach (CartGoodsInputDto dto in inputDtos)
            {
                CartGoods cartGoods = dto.MapTo <CartGoods>();

                if (dto.GoodsId.HasValue && dto.GoodsId.Value > 0)
                {
                    Goods.Models.Goods goods = GoodsRepository.GetByKey(dto.GoodsId.Value);
                    if (goods == null)
                    {
                        throw new Exception("商品不存在");
                    }
                    cartGoods.Goods = goods;
                }

                if (dto.UserId.HasValue && dto.UserId.Value > 0)
                {
                    User user = UserRepository.GetByKey(dto.UserId.Value);
                    if (user == null)
                    {
                        throw new Exception("用户不存在");
                    }
                    cartGoods.User = user;
                }

                if (dto.SkuId.HasValue && dto.SkuId.Value > 0)
                {
                    Goods.Models.Sku sku = SkuRepository.GetByKey(dto.SkuId.Value);
                    if (sku == null)
                    {
                        throw new Exception("Sku不存在");
                    }
                    cartGoods.Sku = sku;
                }

                //判断商品的重复性,如果是相同商品相同规格只改变购物数量
                CartGoods repeatCartGoods = CartGoodsRepository.Entities.SingleOrDefault(cg => cg.User.Id == dto.UserId.Value && cg.Goods.Id == dto.GoodsId.Value && cg.Sku.Id == dto.SkuId.Value);
                if (repeatCartGoods == null)
                {
                    await CartGoodsRepository.InsertAsync(cartGoods);
                }
                else
                {
                    repeatCartGoods.BuyCount += dto.BuyCount;
                    await CartGoodsRepository.UpdateAsync(repeatCartGoods);
                }

                names.Add(cartGoods.Name);
            }

            return(await CartGoodsRepository.UnitOfWork.SaveChangesAsync() > 0
                            ? new OperationResult(OperationResultType.Success, $"“{names.ExpandAndToString()}”创建成功")
                            : OperationResult.NoChanged);
        }
Beispiel #3
0
        /// <summary>
        /// 添加信息信息
        /// </summary>
        /// <param name="inputDtos">要添加的店铺信息DTO信息</param>
        /// <returns>业务操作结果</returns>
        public async Task <OperationResult> AddOrders(params OrderInputDto[] inputDtos)
        {
            //开启事务
            OrderRepository.UnitOfWork.TransactionEnabled = true;
            List <string> names = new List <string>();

            foreach (OrderInputDto dto in inputDtos)
            {
                //auto mapper maybe fileter 不能通过自动映射 数据集合也会映射
                //Models.Order order = dto.MapTo<Models.Order>();

                Models.Order order = new Models.Order()
                {
                    ShopName     = dto.ShopName,
                    OrderNumber  = dto.OrderNumber,
                    Amount       = dto.Amount,
                    HPayAmount   = dto.HPayAmount,
                    RealAmount   = dto.RealAmount,
                    Preferential = dto.Preferential,
                    ExpressFee   = dto.ExpressFee,
                    Remark       = dto.Remark,
                    State        = dto.State
                };

                //店铺
                if (dto.ShopId.HasValue && dto.ShopId.Value > 0)
                {
                    Shop.Models.Shop shop = await ShopRepository.GetByKeyAsync(dto.ShopId.Value);

                    if (shop == null)
                    {
                        return(new OperationResult(OperationResultType.QueryNull, "店铺不存在"));
                    }
                    order.Shop = shop;
                    shop.Orders.Add(order);
                }

                //用户
                if (dto.UserId.HasValue && dto.UserId.Value > 0)
                {
                    User user = await UserRepository.GetByKeyAsync(dto.UserId.Value);

                    if (user == null)
                    {
                        return(new OperationResult(OperationResultType.QueryNull, "用户不存在"));
                    }
                    order.User = user;
                    user.Orders.Add(order);
                }

                //配送信息
                order.OrderExpress = new OrderExpress()
                {
                    Name          = dto.OrderExpress.Name,
                    Region        = dto.OrderExpress.Region,
                    DetailAddress = dto.OrderExpress.DetailAddress,
                    Zip           = dto.OrderExpress.Zip,
                    Mobile        = dto.OrderExpress.Mobile
                };

                //商品
                if (dto.OrderGoodses.Count > 0)
                {
                    foreach (OrderGoodsInputDto orderGoodsDto in dto.OrderGoodses)
                    {
                        //auto mapper maybe filter
                        OrderGoods orderGoods = orderGoodsDto.MapTo <OrderGoods>();

                        //处理商品
                        if (orderGoodsDto.GoodsId.HasValue && orderGoodsDto.GoodsId.Value > 0)
                        {
                            Goods.Models.Goods goods = await GoodsRepository.GetByKeyAsync(orderGoodsDto.GoodsId.Value);

                            if (goods == null)
                            {
                                throw new Exception("商品不存在");
                            }
                            orderGoods.Goods = goods;
                        }
                        await OrderGoodsRepository.InsertAsync(orderGoods);

                        orderGoods.Order = order;
                        order.OrderGoodses.Add(orderGoods);
                    }
                }

                int id = await OrderRepository.InsertAsync(order);

                names.Add(order.OrderNumber);
            }
            return(await OrderRepository.UnitOfWork.SaveChangesAsync() > 0
                ? new OperationResult(OperationResultType.Success, $"订单“{names.ExpandAndToString()}”创建成功")
                : OperationResult.NoChanged);
        }