Exemplo n.º 1
0
        public async Task <DonorsPatientsServiceModel> GetDonorsPatientsByPatientsUserIdAsync(string patientId)
        {
            var donorPatient = await this.context.DonorsPatients.Include(x => x.Patient.User).Where(x => x.Patient.UserId == patientId && x.IsDeleted == false).SingleOrDefaultAsync();

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

            var model = new DonorsPatientsServiceModel
            {
                PatientId = donorPatient.PatientId,
                Patient   = new PatientServiceModel
                {
                    User = new UserServiceModel
                    {
                        Email = donorPatient.Patient.User.Email,
                    },
                    NeededBloodBanks = donorPatient.Patient.NeededBloodBanks,
                },
                DonorId = donorPatient.DonorId,
                Image   = donorPatient.Image,
                ImageId = donorPatient.ImageId,
            };

            return(model);
        }
        public async Task CreateAsync_WithCorectData_ShouldReturnCorectResult()
        {
            var errorMessage = "DonorsPatientsService CreateAsync method does not return properly ";

            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var seeder  = new Seeder();
            await seeder.SeedDonorAsync(context);

            await seeder.SeedPatientAsync(context);

            var userManager           = this.GetUserManagerMock(context);
            var patientService        = new PatientService(context, userManager.Object);
            var donorsPatientsService = new DonorsPatientsService(context, patientService, userManager.Object);
            var donor   = context.Donors.First();
            var patient = context.Patients.First();

            var donorsPatientsServiceModel = new DonorsPatientsServiceModel
            {
                DonorId   = donor.Id,
                PatientId = patient.Id,
            };

            var result = await donorsPatientsService.CreateAsync(donorsPatientsServiceModel);

            var actualResult   = context.DonorsPatients.FirstOrDefault();
            var expectedResult = donorsPatientsServiceModel;

            Assert.True(result);
            Assert.True(actualResult.DonorId == expectedResult.DonorId, errorMessage + "DonorId");
            Assert.True(actualResult.PatientId == expectedResult.PatientId, errorMessage + "PatientId");
        }
Exemplo n.º 3
0
        public async Task <bool> AddImageAsync(DonorsPatientsServiceModel donorsPatientsServiceModel, string imageUrl)
        {
            var donorPatient = await this.context.DonorsPatients.Where(x => x.DonorId == donorsPatientsServiceModel.DonorId && x.PatientId == donorsPatientsServiceModel.PatientId && x.IsDeleted == false).SingleOrDefaultAsync();

            donorPatient.Image = imageUrl;

            var result = await this.context.SaveChangesAsync();

            return(result > 0);
        }
Exemplo n.º 4
0
        public async Task <DonorsPatientsServiceModel> GetDonorsPatientsByDonorsUserIdAsync(string donorId)
        {
            var donorPatient = await this.context.DonorsPatients.Where(x => x.Donor.UserId == donorId && x.IsDeleted == false).Include(x => x.Patient).SingleOrDefaultAsync();

            var patient = await this.patientService.GetByPatientIdAsync(donorPatient.PatientId);

            var model = new DonorsPatientsServiceModel
            {
                PatientId = donorPatient.PatientId,
                Patient   = patient,
                DonorId   = donorPatient.DonorId,
                Image     = donorPatient.Image,
            };

            return(model);
        }
        public async Task <IActionResult> DonorAddPatient(string patientId)
        {
            var user = await this.userManager.GetUserAsync(this.HttpContext.User);

            var donor = await this.donorService.GetByUserIdAsync(user.Id);

            var donorPatient = new DonorsPatientsServiceModel
            {
                PatientId = patientId,
                DonorId   = donor.Id,
            };

            await this.donorsPatientsService.CreateAsync(donorPatient);

            return(this.Redirect("/"));
        }
Exemplo n.º 6
0
        public async Task <bool> DeleteDonorsPatientAsync(DonorsPatientsServiceModel donorsPatientsServiceModel)
        {
            var donorsPatients = await this.context.DonorsPatients.Include(x => x.Donor.User).SingleOrDefaultAsync(x => x.PatientId == donorsPatientsServiceModel.PatientId && x.DonorId == donorsPatientsServiceModel.DonorId);

            donorsPatients.IsDeleted = true;
            donorsPatients.ImageId   = string.Empty;
            donorsPatients.Image     = string.Empty;
            var patient = donorsPatients.Patient;
            var donor   = donorsPatients.Donor;

            await this.userManager.RemoveFromRoleAsync(donor.User, GlobalConstants.DonorRoleName);

            await this.userManager.RemoveFromRoleAsync(patient.User, GlobalConstants.PatientRoleName);

            var result = await this.context.SaveChangesAsync();

            return(result > 0);
        }
Exemplo n.º 7
0
        public async Task <bool> CreateAsync(DonorsPatientsServiceModel donorsPatientsServiceModel)
        {
            var donorPatient = new DonorsPatients
            {
                PatientId = donorsPatientsServiceModel.PatientId,
                DonorId   = donorsPatientsServiceModel.DonorId,
            };

            if (!await this.context.DonorsPatients.ContainsAsync(donorPatient))
            {
                await this.context.DonorsPatients.AddAsync(donorPatient);
            }

            donorPatient.IsDeleted = false;
            var result = await this.context.SaveChangesAsync();

            return(result > 0);
        }
        public async Task AddImageAsync_WithCorectData_ShouldReturnCorectResult()
        {
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var seeder  = new Seeder();
            await seeder.SeedDonorsPatientsAsync(context);

            var userManager                = this.GetUserManagerMock(context);
            var patientService             = new PatientService(context, userManager.Object);
            var donorsPatientsService      = new DonorsPatientsService(context, patientService, userManager.Object);
            var donorPatient               = context.DonorsPatients.First();
            var donorsPatientsServiceModel = new DonorsPatientsServiceModel
            {
                DonorId   = donorPatient.DonorId,
                PatientId = donorPatient.PatientId,
            };

            var actualResult = await donorsPatientsService.AddImageAsync(donorsPatientsServiceModel, "url");

            var expectedResult = donorsPatientsServiceModel;

            Assert.True(actualResult);
        }
        public async Task DeleteDonorsPatientAsync_ShouldDeleteSuccessfully()
        {
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var seeder  = new Seeder();
            await seeder.SeedDonorsPatientsAsync(context);

            var userManager           = this.GetUserManagerMock(context);
            var patientService        = new PatientService(context, userManager.Object);
            var donorsPatientsService = new DonorsPatientsService(context, patientService, userManager.Object);
            var donorPatient          = context.DonorsPatients.First();
            await userManager.Object.AddToRoleAsync(donorPatient.Donor.User, "Donor");

            await userManager.Object.AddToRoleAsync(donorPatient.Patient.User, "Patient");

            var donorsPatientsServiceModel = new DonorsPatientsServiceModel
            {
                DonorId   = donorPatient.DonorId,
                PatientId = donorPatient.PatientId,
                Donor     = new DonorServiceModel
                {
                    User = new UserServiceModel
                    {
                        Id = donorPatient.Donor.User.Id,
                    },
                },
                Patient = new PatientServiceModel
                {
                    User = new UserServiceModel
                    {
                        Id = donorPatient.Patient.User.Id,
                    },
                },
            };

            var actualResult = await donorsPatientsService.DeleteDonorsPatientAsync(donorsPatientsServiceModel);

            Assert.True(actualResult);
        }