Пример #1
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var activity = await _context.Activities.FindAsync(request.Id);

                _context.Remove(activity);
                await _context.SaveChangesAsync();

                return(Unit.Value);
            }
Пример #2
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var activity = await _context.Activities.FindAsync(request.Id);

                //throw custom exception if activity is not found
                if (activity == null)
                {
                    throw new Application.Errors.RestException(HttpStatusCode.NotFound, new { activity = "Activity not found." });
                }

                _context.Remove(activity);

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

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

                throw new Exception("Problem saving changes.");
            }