Esempio n. 1
0
 public int?CreateClient(Client client, HttpPostedFileBase logo, HttpPostedFileBase profile)
 {
     client.Guid = Guid.NewGuid();
     using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions()
     {
         IsolationLevel = IsolationLevel.ReadCommitted,
         Timeout = CommonConfiguration.Configuration.TransactionScope_Timeout
     }))
     {
         var clientId = _clientRepository.Create(client);
         client.CustomizationId = ProcessIncomingCustomization(client.CreateUserId.Value, client.CustomizationId, client.Customization);
         client.AssetLogoId     = ProcessIncomingImage(client.Id, client.CreateUserId.Value, client.AssetLogoId, null, logo);
         client.AssetProfileId  = ProcessIncomingImage(client.Id, client.CreateUserId.Value, client.AssetProfileId, null, profile);
         if (client.AssetLogoId != null || client.AssetProfileId != null)
         {
             _clientRepository.UpdateEntity(client);
         }
         RegistrationCode regCode = new RegistrationCode();
         if (clientId != null && _registrationCodeRepository.Create(clientId.Value, out regCode) &&
             _securityUserClientRepository.Create(client.CreateUserId.Value, client.Id))
         {
             transaction.Complete();
         }
         return(clientId);
     }
 }
        public bool CreateUser(SecurityUser user, string registrationCode)
        {
            bool created = false;

            using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions()
            {
                IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted,
                Timeout = CommonConfiguration.Configuration.TransactionScope_Timeout
            }))
            {
                var regCode = _registrationCodeRepository.Consume(registrationCode);

                if (regCode.Success)
                {
                    user.RegistrationCodeId = regCode.Id;
                    var userid = _securityUserRepository.Create(user);
                    if (regCode.ClientId != null)
                    {
                        var userClient = new SecurityUserClient
                        {
                            ClientId       = regCode.ClientId.Value,
                            CreateUserId   = userid,
                            SecurityUserId = (int)userid,
                        };
                        if (_securityUserClientRepository.Create(userClient))
                        {
                            user.Clients = new List <SecurityUserClient> {
                                userClient
                            };
                        }
                    }
                    if (userid != null && userid > 0 &&
                        (regCode.ClientId == null || user.Clients.Count() > 0))
                    {
                        transaction.Complete();
                        created = true;
                    }
                }
                return(created);
            }
        }