public async Task <Unit> Handle(DescribeStickerCommand request, CancellationToken ct)
        {
            var author = await dbContext.Users.FindOrThrow(request.UserId, ct);

            var sticker = await dbContext.Stickers.FindOrThrow(request.StickerId, ct);

            var descriptions = ExtractDescriptions(request.Description.ToLower()).ToList();

            if (descriptions.IsEmpty())
            {
                throw new ValidationException("Descriptions are empty");
            }

            foreach (var description in descriptions)
            {
                if (string.IsNullOrWhiteSpace(description))
                {
                    continue;
                }

                if (await DescriptionExists(author, sticker, description))
                {
                    continue;
                }

                var stickerDescription = new StickerDescription(author, sticker, description);
                await dbContext.StickerDescriptions.AddAsync(stickerDescription, ct);
            }

            await dbContext.SaveChangesAsync(ct);

            return(Unit.Value);
        }
Exemple #2
0
        public async Task <Unit> Handle(RemoveStickerDescriptionCommand command, CancellationToken ct)
        {
            var description = await context.StickerDescriptions.FindOrThrow(command.DescriptionId, ct);

            context.StickerDescriptions.Remove(description);
            await context.SaveChangesAsync(ct);

            return(Unit.Value);
        }
        public async Task <Unit> Handle(EnsureUserIsRegisteredCommand request, CancellationToken ct)
        {
            var user = await dbContext.Users.FindAsync(request.Id);

            if (user is null)
            {
                user = new User(request.Id);
                dbContext.Users.Add(user);
                await dbContext.SaveChangesAsync(ct);
            }
            return(Unit.Value);
        }
        public async Task <Unit> Handle(EnsureStickerIsRegisteredCommand request, CancellationToken ct)
        {
            var sticker = await dbContext.Stickers.FindAsync(request.StickerId);

            if (sticker is null)
            {
                sticker = new Sticker(request.StickerId, request.StickerFileId);
                dbContext.Stickers.Add(sticker);
                await dbContext.SaveChangesAsync(ct);
            }
            return(Unit.Value);
        }