Exemple #1
0
        public DTO.Account GetAccountByCode(int accountCode)
        {
            var _context   = new InteractiveDBContext();
            var accountDTO = new DTO.Account();
            var account    = _context.Accounts.Where(x => x.Code == accountCode).FirstOrDefault();

            var param        = new SqlParameter("@accountCode", accountCode);
            var transactions = _context.Set <DataLayer.Models.Transaction>().FromSqlRaw("dbo.GetByTransactionByAccountCode @accountCode", param).ToList();


            var config = new MapperConfiguration(cfg => {
                cfg.CreateMap <DataLayer.Models.Account, DTO.Account>();
                cfg.CreateMap <DataLayer.Models.Transaction, DTO.TransactionDTO> ();
            });
            IMapper iMapper         = config.CreateMapper();
            var     transactionsDTO = new List <DTO.TransactionDTO>();

            foreach (var item in transactions)
            {
                var destination = iMapper.Map <DataLayer.Models.Transaction, TransactionDTO>(item);
                transactionsDTO.Add(destination);
            }

            accountDTO.Code                 = account.Code;
            accountDTO.AccountNumber        = account.AccountNumber;
            accountDTO.OutstandingBalance   = account.OutstandingBalance;
            accountDTO.PersonCode           = account.PersonCode;
            accountDTO.PersonCodeNavigation = account.PersonCodeNavigation;
            accountDTO.Transactions         = transactionsDTO;

            return(accountDTO);
        }
        public IActionResult Post([FromBody] DTO.Account accountDTO)
        {
            var newAccount = _mapper.Map <Account>(accountDTO);

            _accountRepo.Add(newAccount);

            return(Created(string.Format("/api/accounts/{0}", newAccount.ID), _mapper.Map <DTO.Account>(newAccount)));
        }
Exemple #3
0
 public Account(DTO.Account account)
 {
     this.Id       = account.Id ?? Guid.NewGuid();
     this.Name     = account.Name;
     this.Password = account.Password;
     this.Email    = account.Email;
     this.Login    = account.Login;
     this.Document = account.Document;
     this.Phone    = account.Phone;
     this.Type     = account.Type;
 }
Exemple #4
0
        public static Models.Account ToModel(this DTO.Account DTOObject)
        {
            //var account = DTOObject.ParseObject<DTO.Account, Models.Account>();
            var customer = DTOObject.customer.ToModel();
            var account  = new Models.Account
            {
                id       = DTOObject.id,
                userId   = customer.id,
                code     = DTOObject.code,
                codeTime = DTOObject.codeTime,
                Customer = customer
            };

            //account.Customer = customer;
            return(account);
        }
Exemple #5
0
        public static DTO.Account ToDTO(this Models.Account model)
        {
            //var account = model.ParseObject<Models.Account, DTO.Account>();
            var customer = model.Customer.ToDTO();
            var account  = new DTO.Account
            {
                id       = model.id,
                userId   = model.Customer.id,
                code     = model.code,
                codeTime = model.codeTime,
                customer = customer
            };

            //account.customer = customer;
            return(account);
        }
        public bool Addacount(DTO.Account accountDTO)
        {
            var _context = new InteractiveDBContext();
            var account  = new DataLayer.Models.Account();

            using (_context)
            {
                account.AccountNumber        = accountDTO.AccountNumber;
                account.Code                 = accountDTO.Code;
                account.OutstandingBalance   = accountDTO.OutstandingBalance;
                account.PersonCode           = accountDTO.PersonCode;
                account.PersonCodeNavigation = accountDTO.PersonCodeNavigation;
                account.Transactions         = (ICollection <Transaction>)accountDTO.Transactions;

                _context.Accounts.Add(account);

                _context.SaveChanges();
            }

            return(true);
        }
Exemple #7
0
        public StoreAccount(Entities.StoreAccount storeAccount)
        {
            Code    = storeAccount.Code;
            Account = new DTO.Account()
            {
                Code     = storeAccount.Account.Code,
                Name     = storeAccount.Account.Customer?.Name ?? storeAccount.Account.Email,
                Email    = storeAccount.Account.Email,
                Document = storeAccount.Account.Document
            };

            Store = new DTO.Store()
            {
                Code = storeAccount.Store.Code,
                Name = storeAccount.Store.Name,
                Cnpj = storeAccount.Store.Cnpj
            };

            SaveDate   = storeAccount.SaveDate;
            UpdateDate = storeAccount.UpdateDate;
        }
Exemple #8
0
        public DTO.Account TransferSimplified()
        {
            var accountSimplified = new DTO.Account();

            accountSimplified.Code            = this.Code;
            accountSimplified.Email           = this.Email;
            accountSimplified.Login           = this.Login;
            accountSimplified.Password        = string.Empty;
            accountSimplified.Document        = string.Empty;
            accountSimplified.DataFingerprint = this.DataFingerprint;
            accountSimplified.Customer        = new Customer()
            {
                Addresses   = new List <Address>(),
                Type        = this.Customer.Type,
                OriginStore = this.Customer.OriginStore,
                Name        = this.Customer.Name,
                SaveDate    = this.Customer.SaveDate,
                UpdateDate  = this.Customer.UpdateDate,
                Status      = this.Customer.Status
            };


            if (this.Customer is DTO.Person)
            {
                accountSimplified.Name = ((DTO.Person) this.Customer).FirstName;
            }
            else
            {
                accountSimplified.Name = ((DTO.Company) this.Customer).CompanyName;
            }

            accountSimplified.Metadata = this.Metadata;
            accountSimplified.Status   = this.Status;
            accountSimplified.Removed  = this.Removed;

            return(accountSimplified);
        }