Пример #1
0
 public void Save(CustomerImport customerImport)
 {
     using (var transaction = Connection.BeginTransaction())
     {
         customerImportRepository.Save(customerImport);
     }
 }
Пример #2
0
        public bool SaveAccount(Requisition requisition, Object account, ApplicationStore applicationStore, IConnection connection)
        {
            var fileRequisition = requisition as FileRequisition;

            var line = (string)account;

            var  properties = line.Split(new char[] { '\t' });
            var  message    = new List <string>();
            bool isValid    = true;

            try
            {
                var result = customerImportFileInfraService.ValidCustomer(properties, fileRequisition);

                if (result.Item1)
                {
                    CustomerImport customer    = result.Item3;
                    var            clientValid = customer.isValid();

                    if (clientValid.Item1)
                    {
                        try
                        {
                            if (customer is CompanyImport)
                            {
                                var company = (CompanyImport)customer;
                            }
                            else
                            {
                                var person = (PersonImport)customer;
                            }
                        }
                        catch (Exception ex)
                        {
                            isValid = false;
                            message.Add(ex.Message);
                        }

                        if (isValid)
                        {
                            if (!IsMemberExists(customer))
                            {
                                customerImportRepository.Save(customer);
                            }
                            else
                            {
                                isValid = false;
                                message.Add("Usuário já existe");
                            }
                        }
                    }
                    else
                    {
                        isValid = false;
                        message.AddRange(clientValid.Item2);
                    }
                }
                else
                {
                    isValid = false;
                    message.AddRange(result.Item2);
                }
            }
            catch (Exception ex)
            {
                isValid = false;
                message.Add(string.Format("{0}", ex.TrimMessage()));
            }

            if (!isValid)
            {
                requisition.RequisitionErrors.Add(new RequisitionError()
                {
                    Code          = Guid.NewGuid(),
                    ErrorMessages = message,
                    Email         = properties.Count() > ConstantsFileImport.Email ? properties[ConstantsFileImport.Email] : string.Empty,
                    Name          = properties.Count() > ConstantsFileImport.FirstName ? properties[ConstantsFileImport.FirstName] : string.Empty
                });
            }

            return(isValid);
        }