Exemplo n.º 1
0
        public async Task <UseCaseResult <Guid> > Handle([NotNull] EditEvent request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var currentDiver = await currentUser.GetCurrentDiverAsync();

            if (currentDiver == null)
            {
                logger.LogError("No diver record found for username [{username}]!", currentUser.Username);
                return(UseCaseResult <Guid> .NotFound());
            }

            var evt = await eventRepository.FindByIdAsync(request.EventId);

            if (evt == null)
            {
                var newEvent = new Domain.Entities.Event(
                    request.Title,
                    request.Description,
                    request.Location,
                    request.MeetingPoint,
                    request.StartTime,
                    request.EndTime,
                    currentDiver.Id);

                await eventRepository.InsertAsync(newEvent);

                return(UseCaseResult <Guid> .Success(newEvent.Id));
            }

            var wasEdited = evt.Edit(
                currentDiver.Id,
                request.Title,
                request.Description,
                request.Location,
                request.MeetingPoint,
                request.StartTime,
                request.EndTime);

            if (!wasEdited)
            {
                return(UseCaseResult <Guid> .Fail(resultCategory : ResultCategory.AccessDenied));
            }

            await eventRepository.UpdateAsync(evt);

            return(UseCaseResult <Guid> .Success(evt.Id));
        }
        public async Task <UseCaseResult <string> > Handle([NotNull] AddMember request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            logger.LogInformation("Adding member [{userName}]", request.UserName, request);

            if (!await currentUser.GetIsAdminAsync())
            {
                logger.LogError("Access denied for user [{currentUser}]!", currentUser.Username);
                return(UseCaseResult <string> .AccessDenied());
            }

            var user = await userManager.FindByNameAsync(request.UserName);

            if (user == null)
            {
                logger.LogError("Identity user [{username}] not found!", request.UserName);
                return(UseCaseResult <string> .NotFound());
            }

            var diver = new Diver(user, request.FirstName, request.LastName);

            await AutoConfirmEmailAddress(user);

            await userManager.AddToRoleAsync(user, Rolenames.Tauchbold);

            await diverRepository.InsertAsync(diver);

            var warningMessage = "";

            if (user.LockoutEnabled)
            {
                logger.LogWarning("User [{username}] is locked out!", request.UserName);
                warningMessage += "Mitglied ist noch gesperrt (LockoutEnabled). ";
            }
            if (!user.EmailConfirmed)
            {
                logger.LogWarning("User [{username}] has not confirmed email address yet!", request.UserName);
                warningMessage += "Mitglied hat seine Emailadresse noch nicht bestätigt!";
            }

            logger.LogInformation("User [{username}] added as a member.", request.UserName);

            return(UseCaseResult <string> .Success(warningMessage.Trim()));
        }
        public async Task <UseCaseResult <IEnumerable <LogbookEntry> > > Handle([NotNull] SummaryListLogbookEntries request, CancellationToken cancellationToken)
        {
            var allEntries = await logbookEntryRepository.GetAllEntriesAsync(false);

            return(UseCaseResult <IEnumerable <LogbookEntry> > .Success(allEntries));
        }