Example #1
0
        public async Task RecreateItem(EntityDto <Guid> input)
        {
            var item = await _itemTerminatedRepository.FirstOrDefaultAsync(input.Id);

            if (item == null)
            {
                throw new UserFriendlyException("此ID的货品不存在");
            }

            var pillar = await _pillarRepository.GetAsync(item.PillarId);

            var category = await _categoryRepository.GetAsync(item.CategoryId);

            var itemDrafting = new ItemDrafting
            {
                Code                = pillar.Code + category.Code + DateTime.Now.Ticks,
                PillarId            = item.PillarId,
                CategoryId          = item.CategoryId,
                StartPrice          = item.StartPrice,
                StepPrice           = item.StepPrice,
                StartTime           = item.StartTime,
                Deadline            = item.Deadline,
                Title               = item.Title,
                Description         = item.Description,
                BiddingCount        = 0,
                HighestBiddingPrice = 0
            };
            await _itemTerminatedRepository.DeleteAsync(input.Id);

            await _itemDraftingRepository.InsertAsync(itemDrafting);
        }
Example #2
0
        public async Task <Guid> CreateItem(CreateItemInputDto input)
        {
            var pillar = await _pillarRepository.GetAsync(input.PillarId);

            var category = await _categoryRepository.GetAsync(input.CategoryId);

            var item = new ItemDrafting
            {
                Code                = pillar.Code + category.Code + DateTime.Now.Ticks,
                PillarId            = input.PillarId,
                CategoryId          = input.CategoryId,
                StartPrice          = input.StartPrice,
                StepPrice           = input.StepPrice,
                StartTime           = input.StartTime,
                Deadline            = input.Deadline,
                Title               = input.Title,
                Description         = input.Description,
                BiddingCount        = 0,
                HighestBiddingPrice = 0,
                InvitationCode      = input.InvitationCode
            };

            if (!input.InvitationCode.IsNullOrEmpty())
            {
                // 根据邀请码获取专场ID
                var activity = await _specialActivityRepository.FirstOrDefaultAsync(s => s.InvitationCode == input.InvitationCode);

                if (activity == null)
                {
                    throw new UserFriendlyException("邀请码不存在");
                }

                item.SpecialActivityId = activity.Id;
            }

            var itemId = await _itemDraftingRepository.InsertAndGetIdAsync(item);

            for (int i = 0; i < input.PictureList.Count; i++)
            {
                var p = await _itemPicRepository.GetAsync(input.PictureList[i].Id);

                p.IsCover = input.PictureList[i].IsCover;
                p.ItemId  = itemId;
                p.Index   = i + 1;
                await _itemPicRepository.UpdateAsync(p);
            }

            return(itemId);
        }