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));
        }
예제 #2
0
        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));
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
        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));
        }