Пример #1
0
        public ActionResult MyServices()
        {
            MyServicesViewModel model = new MyServicesViewModel();

            model.Transactions = new List <TransactionInfoViewModel>();
            var currentUser = db.Users.Where(m => m.UserName == User.Identity.Name).FirstOrDefault();

            if (currentUser != null)
            {
                var accounts     = db.Accounts.Where(m => m.UserId == currentUser.Id).ToList();
                var trans        = new List <Transaction>();
                var transactions = new List <Transaction>();
                foreach (var account in accounts)
                {
                    trans = db.Transactions.Where(m => m.SenderId == account.AccountId).ToList();
                    if (trans != null)
                    {
                        foreach (var transaction in trans)
                        {
                            if (transaction.SaveToMyTransfers == true)
                            {
                                var transactionInfo = new TransactionInfoViewModel();
                                transactionInfo.TransactionName = transaction.TransactionName;
                                transactionInfo.SenderIban      = account.Iban;
                                transactionInfo.Amount          = transaction.Amount;
                                transactionInfo.Created         = transaction.Created;
                                var receiver = db.Accounts.Where(m => m.AccountId == transaction.ReceiverId).FirstOrDefault();
                                if (receiver == null)
                                {
                                    var acc = db.Accounts.Where(m => m.UserId.Equals(transaction.ReceiverId.ToString())).FirstOrDefault();
                                    transactionInfo.ReceiverIban     = acc.Iban;
                                    transactionInfo.ReceiverCurrency = acc.Currency;
                                }
                                else
                                {
                                    transactionInfo.ReceiverIban     = receiver.Iban;
                                    transactionInfo.ReceiverCurrency = receiver.Currency;
                                }
                                transactionInfo.SenderCurrency = account.Currency;
                                transactionInfo.TransactionId  = transaction.TransactionId;
                                model.Transactions.Add(transactionInfo);
                            }
                        }
                    }
                }

                return(View(model));
            }

            return(RedirectToAction("InvalidUser", "Account"));
        }
Пример #2
0
    public TransactionInfoViewModel MapToDto(TransactionEntity entity)
    {
        var dto = new TransactionInfoViewModel
        {
            Id          = entity.Id,
            Amount      = entity.Amount,
            Date        = entity.Date,
            Description = entity.Description,
            Tags        = _tagsMapper.Map(entity.Tags).ToImmutableArray(),
            Account     = _accountMapper.MapToAccountInfoViewModel(entity.Account),
            Category    = _categoryMapper.MapToCategoryInfoViewModel(entity.Category)
        };

        return(dto);
    }
Пример #3
0
        public ActionResult TransactionHistory()
        {
            TransactionHistoryViewModel model = new TransactionHistoryViewModel();

            model.Transactions = new List <TransactionInfoViewModel>();
            var user = db.Users.Where(m => m.UserName.Equals(User.Identity.Name)).FirstOrDefault();

            if (user != null)
            {
                var transactions = new List <Transaction>();

                var accounts = db.Accounts.Where(m => m.UserId.Equals(user.Id)).ToList();

                foreach (var account in accounts)
                {
                    transactions.AddRange(db.Transactions.Where(m => m.ReceiverId == account.AccountId).ToList());
                    transactions.AddRange(db.Transactions.Where(m => m.SenderId == account.AccountId && account.UserId != user.Id).ToList());
                }


                foreach (var transaction in transactions)
                {
                    var transactionInfo = new TransactionInfoViewModel();
                    transactionInfo.Created = transaction.Created;
                    transactionInfo.Amount  = transaction.Amount;
                    transactionInfo.Details = transaction.Details;
                    var sender   = db.Accounts.Where(m => m.AccountId == transaction.SenderId).FirstOrDefault();
                    var receiver = db.Accounts.Where(m => m.AccountId == transaction.ReceiverId).FirstOrDefault();
                    transactionInfo.ReceiverIban     = receiver.Iban;
                    transactionInfo.SenderIban       = sender.Iban;
                    transactionInfo.SenderCurrency   = sender.Currency;
                    transactionInfo.ReceiverCurrency = receiver.Currency;
                    if (sender.UserId == user.Id)
                    {
                        transactionInfo.Type = "out";
                    }
                    else
                    {
                        transactionInfo.Type = "in";
                    }

                    model.Transactions.Add(transactionInfo);
                }
                return(View(model));
            }
            return(RedirectToAction("InvalidUser", "Home"));
        }
        public void OrganizationManagementService_MakeTransaction()
        {
            ApplicationDbContext applicationDb = new ApplicationDbContext();

            applicationDb.Database.CreateIfNotExists();

            OrganizationType organizationType = new OrganizationType()
            {
                Id   = Guid.NewGuid(),
                Name = "TestType_03"
            };

            applicationDb.OrganizationTypes.Add(organizationType);
            applicationDb.SaveChanges();

            Organization organization = new Organization()
            {
                Id                 = Guid.NewGuid(),
                FullName           = "TestCompany_03",
                RegistrationDate   = DateTime.Now,
                OrganizationTypeId = organizationType.Id
            };

            applicationDb.Organizations.Add(organization);
            applicationDb.SaveChanges();

            TransactionInfoViewModel model = new TransactionInfoViewModel()
            {
                TransactionTypeName = "Deposit",
                Sum              = 145000.50M,
                Description      = "test transaction",
                OrganizationId   = organization.Id.ToString(),
                OrganizationName = organization.FullName
            };

            OrganizationManagementService sut = new OrganizationManagementService();

            sut.MakeTransaction(model);

            Transaction transaction = applicationDb.Transactions.SingleOrDefault(p => p.OrganizationId == organization.Id);

            Assert.IsNotNull(transaction);
            Assert.IsTrue(transaction.Sum == model.Sum && transaction.TransactionType.Equals(TransactionType.Deposit));
        }
Пример #5
0
        public ActionResult FilledTransfer(TransactionInfoViewModel model)
        {
            TransfersViewModel filled = new TransfersViewModel();
            var transaction           = db.Transactions.Where(m => m.TransactionId == model.TransactionId).FirstOrDefault();

            if (transaction != null)
            {
                var sender   = db.Accounts.Where(m => m.AccountId.Equals(transaction.SenderId)).FirstOrDefault();
                var receiver = db.Accounts.Where(m => m.AccountId.Equals(transaction.ReceiverId)).FirstOrDefault();
                var destUser = db.Users.Where(m => m.Id.Equals(receiver.UserId)).FirstOrDefault();
                filled.DestIban   = receiver.Iban;
                filled.SenderIban = sender.Iban;
                filled.Details    = transaction.Details;
                filled.DestName   = destUser.NameIdentifier;
                filled.Amount     = 0;
                return(View("FilledTransfer", filled));
            }
            else
            {
                return(RedirectToAction("Home", "Home"));
            }
        }
        public void MakeTransaction(TransactionInfoViewModel model)
        {
            var organization = _applicationDbContext.Organizations
                               .SingleOrDefault(p => p.FullName == model.OrganizationName || p.Id.ToString() == model.OrganizationId);

            if (organization == null)
            {
                throw new Exception($"Организации с таким наименованием {model.OrganizationName} в базе не существует");
            }
            var transactionType = model.TransactionTypeName == TransactionType.Deposit.ToString() ? TransactionType.Deposit : TransactionType.Withdraw;

            Transaction transaction = new Transaction()
            {
                Id = Guid.NewGuid(),
                TransactionType = transactionType,
                Sum             = model.Sum,
                TransactionDate = DateTime.Now,
                Description     = model.Description,
                OrganizationId  = organization.Id
            };

            _applicationDbContext.Transactions.Add(transaction);
            _applicationDbContext.SaveChanges();
        }