Esempio n. 1
0
        public void RemoveMember(string email, string document)
        {
            var customers = new List <CustomerImport>();

            customers.AddRange(customerImportRepository.GetByEmail(email));

            if (document.IsValidCPF())
            {
                customers.AddRange(customerImportRepository.GetByCPF(document));
            }
            else if (document.IsValidCNPJ())
            {
                customers.AddRange(customerImportRepository.GetByCNPJ(document));
            }


            customers.ForEach(customer =>
            {
                customer.Password   = string.Empty;
                customer.Removed    = true;
                customer.UpdateDate = DateTime.Now;
                customerImportRepository.Update(customer);
            });
        }
Esempio n. 2
0
        public void CreatePassword(Guid memberCode, string tokenCode, string newPassword, Guid?clientId = null)
        {
            using (var transaction = Connection.BeginTransaction())
            {
                try
                {
                    var customerImport = customerImportRepository.Get(memberCode);

                    if (passwordPolicy == null || passwordPolicy.Validate(customerImport.Email, newPassword))
                    {
                        customerImport.Password = newPassword.Encrypt();
                        customerImport.HandleCustomer();

                        var listAppStore     = new List <ApplicationStore>();
                        var applicationStore = applicationStoreRepository.GetByClientId(clientId.Value);

                        if (applicationStore.IsNull())
                        {
                            throw new ArgumentException("Aplicação inválida");
                        }

                        listAppStore.Add(applicationStore);

                        if (customerImport.StoreCode.HasValue)
                        {
                            var appsStore = applicationStoreRepository.GetByStore(customerImport.StoreCode.Value);

                            if (appsStore.IsNull())
                            {
                                throw new ArgumentException("Loja sem aplicações");
                            }

                            var appECStore = appsStore.FirstOrDefault(s => s.Application.Name.ToLower() == "ec-loja");

                            if (appECStore.IsNull())
                            {
                                throw new ArgumentException("Aplicação EC-Loja não encontrada");
                            }

                            listAppStore.Add(appECStore);
                        }
                        else
                        {
                            throw new ArgumentException("Código da loja não preenchido");
                        }

                        Customer customer;
                        if (customerImport is CompanyImport)
                        {
                            customer = new Company(customerImport);
                        }
                        else
                        {
                            customer = new Person(customerImport);
                        }

                        var _accounts = new Account()
                        {
                            Email    = customerImport.Email,
                            Login    = customerImport.Email,
                            Document = customerImport.DisplayDocument,
                            Password = newPassword,
                            Customer = customer,
                            Status   = customerImport.Status,
                            Removed  = false
                        };

                        listAppStore.ForEach(x =>
                        {
                            _accounts.ConnectApp(x);
                        });

                        Role _role;
                        listAppStore.ForEach(x =>
                        {
                            _role = roleRepository.GetByApplication(x.ApplicationCode, x.StoreCode);

                            if (!_role.IsNull())
                            {
                                _accounts.ConnectRole(_role);
                            }
                        });

                        var accountDO = accountService.Get(customerImport.Email, customerImport.DisplayDocument, applicationStore, true);

                        if (accountDO.IsNull())
                        {
                            accountService.Add(_accounts, applicationStore, customerImport.StoreCode.Value);
                        }
                        else
                        {
                            accountService.Update(_accounts);
                        }

                        customerImport.Password   = string.Empty;
                        customerImport.Removed    = true;
                        customerImport.UpdateDate = DateTime.Now;
                        customerImportRepository.Update(customerImport);
                    }
                    else
                    {
                        throw new ArgumentException("senha inválida.");
                    }

                    resetPasswordTokenRepository.Delete(tokenCode);

                    transaction.Commit();
                }
                catch
                {
                    transaction.Rollback();
                    throw;
                }
            }

            if (clientId.HasValue && !clientId.Value.IsEmpty())
            {
                using (var transaction = Connection.BeginTransaction())
                {
                    try
                    {
                        var store = applicationStoreRepository.GetByClientId(clientId.Value).Store;

                        passwordLogRepository.Save(new PasswordLog(memberCode, PasswordEventLog.RecoveryCustomerImport, store.Code));

                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Rollback();
                    }
                }
            }
        }