Exemple #1
0
        public async Task <Unit> Handle(DeleteCommand request, CancellationToken cancellationToken)
        {
            var activity = await context.Activities.FindAsync(request.Id);

            if (activity == null)
            {
                throw new Exception("Activity not found");
            }

            context.Remove(activity);

            var result = await context.SaveChangesAsync() > 0;

            if (result)
            {
                return(Unit.Value);
            }

            throw new Exception("Problem saving changes");
        }
        public async Task <Unit> Handle(DeleteActivityCommand request, CancellationToken cancellationToken)
        {
            var activity = await _context.Activities.FindAsync(request.Id);

            if (activity == null)
            {
                throw new RestException(HttpStatusCode.NotFound, "Could not find activity.");
            }

            _context.Remove(activity);

            var success = await _context.SaveChangesAsync(cancellationToken) > 0;

            if (success)
            {
                return(Unit.Value);
            }

            throw new Exception("Error during save changes.");
        }
Exemple #3
0
            public async Task <Result <Unit> > Handle(Command request, CancellationToken cancellationToken)
            {
                var activity = await _context.Activities.FindAsync(request.Id);

                if (activity == null)
                {
                    return(null);
                }

                _context.Remove(activity);

                var result = await _context.SaveChangesAsync() > 0;

                if (!result)
                {
                    return(Result <Unit> .Failure("Failed to delete the activity"));
                }

                return(Result <Unit> .Success(Unit.Value));
            }