コード例 #1
0
 public static DonorAnalysisModelView toDonorRegistrationForDonationModelView(DonorRegistrationForDonation d)
 {
     return(new DonorAnalysisModelView
     {
         CNP = d.CNP,
         Name = d.Name,
         Surname = d.Surname,
         BirthDate = d.BirthDate.ToString(),
         CityOfBirth = d.CityOfBirth,
         CountyOfBirth = d.CountyOfBirth,
         CurrentCity = d.CurrentCity,
         CurrentCounty = d.CurrentCounty,
         Age = d.Age,
         Weigth = d.Weigth,
         BeatsPerMiute = d.BeatsPerMiute,
         BloodPressure = d.BloodPressure,
         HadSurgery = d.HadSurgery.ToString(),
         PersonSex = d.PersonSex.ToString(),
         PregnancyStatus = d.PregnancyStatus.ToString(),
         Period = d.Period,
         HeartDisease = d.HeartDisease,
         Hypertension = d.Hypertension,
         KidneyDisease = d.KidneyDisease,
         MentalIlness = d.MentalIlness,
         LiverDisease = d.LiverDisease,
         EndocrineDisease = d.EndocrineDisease,
         Hepatitis = d.Hepatitis,
         Tuberculosis = d.Tuberculosis,
         Pox = d.Pox,
         Malaria = d.Malaria,
         Epilepsy = d.Epilepsy,
         MindIlnesses = d.MindIlnesses,
         Brucellosis = d.Brucellosis,
         Ulcer = d.Ulcer,
         Diabetes = d.Diabetes,
         HeartDiseases = d.HeartDiseases,
         SkinDiseases = d.SkinDiseases,
         Myopia = d.Myopia,
         Cancer = d.Cancer,
         Email = d.Email,
         PhoneNumber = d.PhoneNumber,
         OtherPersonName = d.OtherPersonName,
         OtherPersonSurname = d.OtherPersonSurname,
         RegistrationDate = d.RegistrationDate.ToString()
     });
 }
コード例 #2
0
        public async Task AddRegistrationForDonation(DonorRegistrationForDonation donorRegistrationForDonation, UserManager <ApplicationUser> userManager, RoleManager <IdentityRole> roleManager)
        {
            using (UnitOfWork uow = new UnitOfWork())
            {
                donorRegistrationForDonation.RegistrationDate = DateTime.Now;
                //var donorId = uow.DonorRepository.GetAll().Where(d => d.CNP == donorRegistrationForDonation.CNP).First().Id;
                try
                {
                    donorRegistrationForDonation.DonorId = uow.DonorRepository.GetByFunc(donor => donor.CNP == donorRegistrationForDonation.CNP).Id;
                    donorRegistrationForDonation.Donor   = uow.DonorRepository.GetByFunc(donor => donor.CNP == donorRegistrationForDonation.CNP);
                } catch (Exception) {
                    var address = new Address
                    {
                        City   = donorRegistrationForDonation.CurrentCity,
                        County = donorRegistrationForDonation.CurrentCounty,
                        Street = "UNKNOWN",
                        Number = 0
                    };

                    await userManager.CreateAsync(new ApplicationUser { Email = donorRegistrationForDonation.Email, UserName = donorRegistrationForDonation.Email }, "Password123.");

                    var donorAccount = await userManager.FindByEmailAsync(donorRegistrationForDonation.Email);

                    var role = await roleManager.FindByNameAsync("Donor");

                    await userManager.AddToRoleAsync(donorAccount, role.Name);

                    donorRegistrationForDonation.Donor = new Donor
                    {
                        CNP       = donorRegistrationForDonation.CNP,
                        Address   = address,
                        FirstName = donorRegistrationForDonation.Name,
                        LastName  = donorRegistrationForDonation.Surname,
                        Id        = donorAccount.Id
                    };

                    uow.DonorRepository.Add(donorRegistrationForDonation.Donor);
                }

                uow.DonorRegistrationForDonationRepository.Add(donorRegistrationForDonation);
                uow.Save();
            }
        }