示例#1
0
        public async Task <IActionResult> Table()
        {
            var user = await _userManager.GetUserAsync(HttpContext.User); //Current logged user

            var movements = new MovementsViewModel();

            var natural = await GetNaturalAsync(user.Id);

            if (natural != null)
            {
                movements.DepositCertificates.AddRange(
                    natural.SavingAccounts[DefaultAccount].DepositCertificates
                    .OrderBy(certificate => certificate.DateHour));
                movements.WithdrawalCertificates.AddRange(
                    natural.SavingAccounts[DefaultAccount].WithdrawalCertificates
                    .OrderBy(certificate => certificate.DateHour));
                return(View("Table", movements));
            }

            var juridic = await GetJuridicAsync(user.Id);

            if (juridic != null)
            {
                movements.DepositCertificates.AddRange(juridic.SavingAccounts[DefaultAccount].DepositCertificates
                                                       .OrderBy(certificate => certificate.DateHour));
                movements.WithdrawalCertificates.AddRange(juridic.SavingAccounts[DefaultAccount].WithdrawalCertificates
                                                          .OrderBy(certificate => certificate.DateHour));
                return(View("Table", movements));
            }

            return(NotFound());
        }
示例#2
0
        public MovementsViewModel JsonToMovementsViewModels(JToken json)
        {
            var movementsViewModel = new MovementsViewModel();
            var noko = ParseObjectProperties(movementsViewModel, json);

            return(movementsViewModel);
        }
示例#3
0
 //Loop through all the properties
 private static void AddValueToMovementsModel(object movement, ref MovementsViewModel movementsViewModel)
 {
     foreach (var property in movementsViewModel.GetType().GetProperties())
     {
         var propertyValue = GetPropertyValue(movement, property.Name);
         if (propertyValue != null)
         {
             SetPropertyValueToMovementsViewModel(property.Name, propertyValue, ref movementsViewModel);
         }
     }
 }
        public void AddValuesToMovementsViewModelTests()
        {
            var jsonArray = TestsHelper.GetJonsArrayFromFile("TransactionsArray.json");
            List <AccountMovement> accountMovements = ModelConverter.GetAccountMovmentsFromJarray(jsonArray);

            accountMovements.Count.Should().Be(122);
            MovementsViewModel movementViewModel = new MovementsViewModel();

            ModelConverter.AddValuesToMovementsViewModel(accountMovements[0], ref movementViewModel);

            movementViewModel.Amount.Should().Be(35);
        }
示例#5
0
 //Loop through all the properties
 public static void AddValuesToMovementsViewModel(object movement, ref MovementsViewModel movementsViewModel)
 {
     foreach (var property in movementsViewModel.GetType().GetProperties())
     {
         var propertyValue = GetPropertyValue(movement, property.Name);
         if (propertyValue != null)
         {
             var properties = GetPropertiesNamesFromObject(movementsViewModel);
             if (properties.Contains(property.Name))
             {
                 movementsViewModel.GetType().GetProperty(property.Name)?.SetValue(movementsViewModel, propertyValue);
             }
         }
     }
 }
示例#6
0
        public static List <MovementsViewModel> CreateMovementsViewModels(List <AccountMovement> accountMovements, List <SubCategory> subCategories, string acountName)
        {
            var moventsViewModel = new List <MovementsViewModel>();

            foreach (var movement in accountMovements)
            {
                MovementsViewModel movementViewModel = new MovementsViewModel()
                {
                    AcountName = acountName
                };

                // Add values to model if it find same property name
                AddValueToMovementsModel(movement, ref movementViewModel);

                movementViewModel = UpdateMovementViewModelWithSubCategory(subCategories, movementViewModel);

                moventsViewModel.Add(movementViewModel);
            }
            AddUnspecifiedTransaction(ref moventsViewModel);
            return(moventsViewModel);
        }
示例#7
0
 public ModelViewBuilder()
 {
     _model = new MovementsViewModel();
 }
示例#8
0
 public static bool SetPropertyValueToMovementsViewModel(string propertyName, object propertyValue, ref MovementsViewModel modelToUpdate)
 {
     try
     {
         var properties = GetPropertiesNamesFromObject(modelToUpdate);
         if (properties.Contains(propertyName))
         {
             modelToUpdate.GetType().GetProperty(propertyName).SetValue(modelToUpdate, propertyValue);
             return(true);
         }
         return(false);
     }
     catch
     {
         return(false);
     }
 }
示例#9
0
        public static MovementsViewModel UpdateMovementViewModelWithSubCategory(List <SubCategory> subCategories, MovementsViewModel movementModel)
        {
            try
            {
                if (!string.IsNullOrEmpty(movementModel.Text))
                {
                    var subcategoriesMatch = subCategories.Where(sub => CultureInfo.InvariantCulture.CompareInfo.LastIndexOf(movementModel.Text, sub.KeyWord.ToLower(), CompareOptions.IgnoreCase) >= 0);

                    if (subcategoriesMatch != null && subcategoriesMatch.Count() > 0)
                    {
                        if (subcategoriesMatch.Count() == 1)
                        {
                            AddValueToMovementsModel(subcategoriesMatch.FirstOrDefault(), ref movementModel);
                        }
                        else
                        {
                            AddValueToMovementsModel(AddSubcategoriesToMovement(subcategoriesMatch), ref movementModel);
                        }
                    }
                }
            }
            catch
            {
                //
            }
            return(movementModel);
        }
示例#10
0
 public async Task <int> CreateMovement(MovementsViewModel model)
 {
     _context.Add(model);
     return(await _context.SaveChangesAsync());
 }
        public async Task <IActionResult> Create(MovementsViewModel movementsViewModel)
        {
            if (ModelState.IsValid)
            {
                ClaimsPrincipal currentUser = this.User;
                Guid            movementId  = Guid.NewGuid();
                var             movements   = new MovementsViewModel
                {
                    Id                 = movementId,
                    UserGuid           = currentUser.FindFirst(ClaimTypes.Name).Value,
                    AmountIn           = movementsViewModel.AmountIn,
                    AmountOut          = movementsViewModel.AmountOut,
                    BankAccountGuidIn  = movementsViewModel.BankAccountGuidIn,
                    BankAccountGuidOut = movementsViewModel.BankAccountGuidOut,
                    CorrelationId      = null
                };
                if (movementsViewModel.AmountInS > 0)
                {
                    movements.Comission = (movementsViewModel.Comission / 2);
                }
                else
                {
                    movements.Comission = (movementsViewModel.Comission);
                }
                movements.ComissionBadge = movementsViewModel.ComissionBadge;
                await _movementsServices.CreateMovement(movementsViewModel);

                var accountIn = await _bankServices.GetBank(movements.BankAccountGuidIn);

                var accountOut = await _bankServices.GetBank(movements.BankAccountGuidOut);

                movements.BadgeIn  = accountIn.Currency;
                movements.BadgeOut = accountOut.Currency;
                accountIn.Amount  += movements.AmountIn;
                accountOut.Amount -= movements.AmountOut;
                await _bankServices.UpdateAmount(accountIn, accountOut);

                if (movementsViewModel.AmountInS > 0)
                {
                    var movementsS = new MovementsViewModel
                    {
                        Id                 = Guid.NewGuid(),
                        UserGuid           = currentUser.FindFirst(ClaimTypes.Name).Value,
                        AmountIn           = movementsViewModel.AmountInS,
                        AmountOut          = movementsViewModel.AmountOutS,
                        BadgeIn            = movementsViewModel.BadgeInS,
                        BadgeOut           = movementsViewModel.BadgeOutS,
                        BankAccountGuidIn  = movementsViewModel.BankAccountGuidInS,
                        BankAccountGuidOut = movementsViewModel.BankAccountGuidOutS,
                        CorrelationId      = movementId,
                        Comission          = (movementsViewModel.Comission / 2)
                    };
                    await _movementsServices.CreateMovement(movementsViewModel);

                    var accountInS = await _bankServices.GetBank(movementsS.BankAccountGuidIn);

                    var accountOutS = await _bankServices.GetBank(movementsS.BankAccountGuidOut);

                    accountIn.Amount  += movementsS.AmountIn;
                    accountOut.Amount -= movementsS.AmountOut;
                    await _bankServices.UpdateAmount(accountInS, accountOutS);
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(movementsViewModel));
        }