Пример #1
0
        void IUnitOfWork.Save(AbstractDomainModel domainModel)
        {
            try
            {
                providerRegistration = (ProviderRegistration)domainModel;
                User             user            = null;
                Provider         provider        = null;
                ProviderPractice poviderPractice = new ProviderPractice();
                Practice         practice        = null;

                user = userRepository.GetByName(providerRegistration.Name);
                if (user == null)
                {
                    user               = new User();
                    user.UserId        = providerRegistration.Name;
                    user.Password      = CareHub.Core.Common.Encryption.Encrypt("#", providerRegistration.Password);
                    user.UserRoleId    = 1;
                    user.Enable        = true;
                    user.Locked        = false;
                    user.LastLoginDate = DateTime.Now;
                }
                else
                {
                    throw new Exception("User name already exist. Please login using the existing user name.");
                }

                provider = providerRepository.GetByName(providerRegistration.Name);
                if (provider == null)
                {
                    provider              = new Provider();
                    provider.UserId       = providerRegistration.Name;
                    provider.FirstName    = providerRegistration.Name;
                    provider.ScreenName   = providerRegistration.Name;
                    provider.GenderId     = providerRegistration.Gender;
                    provider.MobileNumber = providerRegistration.MobileNumber;
                    provider.Email        = providerRegistration.Email;
                    provider.IsActive     = true;
                    provider.SignUpDate   = DateTime.Now;
                }
                else
                {
                    throw new Exception("Provider name already exist. Please use different provider name.");
                }
                practice = practiceRepository.GetByName(providerRegistration.ClinicName);
                if (practice == null)
                {
                    practice              = new Practice();
                    practice.Name         = providerRegistration.ClinicName;
                    practice.CountryId    = providerRegistration.CountryId;
                    practice.CityId       = providerRegistration.CityId;
                    practice.LocalityId   = providerRegistration.LocalityId;
                    practice.CreationDate = DateTime.Now;
                    practice.Address      = providerRegistration.ClinicAddress;
                }


                poviderPractice          = new ProviderPractice();
                poviderPractice.Provider = provider;
                poviderPractice.Practice = practice;


                userRepository.Save(user);
                providerRepository.Save(provider);
                practiceRepository.Save(practice);
                providerPracticeRepository.Save(poviderPractice);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }