Esempio n. 1
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                SectionAppointment sectionAppointment = await _arpaContext.SectionAppointments
                                                        .FirstOrDefaultAsync(sa => sa.SectionId == request.SectionId && sa.AppointmentId == request.Id, cancellationToken);

                _arpaContext.SectionAppointments.Remove(sectionAppointment);

                if (await _arpaContext.SaveChangesAsync(cancellationToken) > 0)
                {
                    _arpaContext.ClearChangeTracker();
                    return(Unit.Value);
                }

                throw new Exception("Problem removing section appointment");
            }
Esempio n. 2
0
            public async Task <Unit> Handle(Command <TEntity> request, CancellationToken cancellationToken)
            {
                TEntity entityToDelete = await _arpaContext.FindAsync <TEntity>(new object[] { request.Id }, cancellationToken);

                if (entityToDelete == null)
                {
                    throw new ValidationException(new[] { new ValidationFailure(nameof(request.Id), $"The {typeof(TEntity).Name} could not be found.") });
                }

                _arpaContext.Remove(entityToDelete);

                if (await _arpaContext.SaveChangesAsync(cancellationToken) > 0)
                {
                    _arpaContext.ClearChangeTracker();
                    return(Unit.Value);
                }

                throw new Exception($"Problem deleting {typeof(TEntity).Name}");
            }