public async Task <DonationViewModel> Handle(CreateDonationCommand request, CancellationToken cancellationToken) { var entity = new Donation() { DonorId = request.DonorId, UnitsOfBlood = request.UnitsOfBlood, DonationDate = request.DonationDate }; dbContext.Donations.Add(entity); await dbContext.SaveChangesAsync(cancellationToken); return(mapper.Map <DonationViewModel>(entity)); }
public async Task <Unit> Handle(DeleteAppointmentCommand request, CancellationToken cancellationToken) { var entity = await dbContext.Appointments.FindAsync(request.AppointmentId); if (entity != null) { dbContext.Appointments.Remove(entity); await dbContext.SaveChangesAsync(cancellationToken); } else { throw new NotFoundException(nameof(Appointment), request.AppointmentId); } return(Unit.Value); }
public async Task <AppointmentViewModel> Handle(CreateAppointmentCommand request, CancellationToken cancellationToken) { var entity = new Appointment() { DonorId = request.DonorId, LocationId = request.LocationId, StartDate = request.StartDate, EndDate = request.StartDate.AddMinutes(60) }; dbContext.Appointments.Add(entity); await dbContext.SaveChangesAsync(cancellationToken); return(mapper.Map <AppointmentViewModel>(entity)); }
public async Task <DonationViewModel> Handle(UpdateDonationCommand request, CancellationToken cancellationToken) { var entity = await dbContext.Donations.FindAsync(request.DonationId); if (entity != null) { entity.DonorId = request.DonorId; entity.UnitsOfBlood = request.UnitsOfBlood; entity.DonationDate = request.DonationDate; await dbContext.SaveChangesAsync(cancellationToken); return(mapper.Map <DonationViewModel>(entity)); } else { throw new NotFoundException(nameof(Donation), request.DonationId); } }
public async Task <AppointmentViewModel> Handle(UpdateAppointmentCommand request, CancellationToken cancellationToken) { var entity = await dbContext.Appointments.FindAsync(request.AppointmentId); if (entity != null) { entity.DonorId = request.DonorId; entity.StartDate = request.StartDate; entity.EndDate = request.StartDate.AddHours(60); entity.LocationId = request.LocationId; await dbContext.SaveChangesAsync(cancellationToken); return(mapper.Map <AppointmentViewModel>(entity)); } else { throw new NotFoundException(nameof(Appointment), request.AppointmentId); } }
public async Task <DonorViewModel> Handle(CreateDonorCommand request, CancellationToken cancellationToken) { Donor entity = new Donor { DonorId = request.DonorId, FirstName = request.FirstName, MiddleInital = request.MiddleInital, LastName = request.LastName, Gender = request.Gender, DateOfBirth = request.DateOfBirth, BloodTypeId = request.BloodTypeId }; DbContext.Donors.Add(entity); await DbContext.SaveChangesAsync(cancellationToken); DonorViewModel response = Mapper.Map <DonorViewModel>(entity); return(response); }
public async Task <DonorViewModel> Handle(UpdateDonorCommand request, CancellationToken cancellationToken) { // check to see if donor exist var entity = await dbContext.Donors.FindAsync(request.DonorId); if (entity != null) { entity.FirstName = request.FirstName; entity.MiddleInital = request.MiddleInital; entity.LastName = request.LastName; entity.Gender = request.Gender; entity.DateOfBirth = request.DateOfBirth; entity.BloodTypeId = request.BloodTypeId; await dbContext.SaveChangesAsync(cancellationToken); } else { throw new NotFoundException(nameof(Donor), request.DonorId); } return(mapper.Map <DonorViewModel>(entity)); }