Esempio n. 1
0
        public async Task <ApiRequestResult> AddAsync(CouponDto dto)
        {
            var command = dto.EntityMap <CouponDto, Coupon>();

            command.Id = Guid.NewGuid();
            if (dto.ProductRelationList.Count > 0)
            {
                var newEntitys = dto.ProductRelationList.Select(c => new CouponProductRelation
                {
                    CouponId    = command.Id,
                    ProductId   = c.ProductId,
                    ProductName = c.ProductName,
                    ProductSn   = c.ProductSn,
                }).ToList();
                await _couponProductRelationRepository.MultiAddAsync(newEntitys);
            }

            if (dto.ProductCategoryRelationList.Count > 0)
            {
                var newEntitys = dto.ProductCategoryRelationList.Select(c => new CouponProductCategoryRelation
                {
                    CouponId            = command.Id,
                    ProductCategoryId   = c.ProductCategoryId,
                    ProductCategoryName = c.ProductCategoryName,
                    ParentCategoryName  = c.ParentCategoryName,
                }).ToList();
                await _couponProductCategoryRelationRepository.MultiAddAsync(newEntitys);
            }
            await _couponRepository.AddAsync(command);

            return(ApiRequestResult.Success("添加成功"));
        }