Ejemplo n.º 1
0
        public string CreateAccessToken()
        {
            var user = userService.GetAuthenticatedUser();

            var accessToken = storageClient.GetAccessToken(user.Id);

            return(accessToken.ToString());
        }
Ejemplo n.º 2
0
        public OperationResult Add(AccountModel accountModel)
        {
            using (var accountRepository = repositoryFactory.CreateAccountRepository())
            {
                var user = userService.GetAuthenticatedUser();

                var entity = accountMapper.ToEntity(accountModel);
                entity.UserId = user.Id;
                accountRepository.Add(entity);
                accountRepository.Commit();
            }
            return(OperationResult.Succeed());
        }
Ejemplo n.º 3
0
        public IEnumerable <MonthlyExpenseModel> GetMonthlyExpenses()
        {
            using (var monthlyExpenseRepository = repositoryFactory.CreateMonthlyExpenseRepository())
            {
                var user = userSessionService.GetAuthenticatedUser();

                var MonthlyExpenses = monthlyExpenseRepository
                                      .Where(x => x.UserId.Equals(user.Id))
                                      .Select(x => monthlyExpenseMapper.ToModel(x))
                                      .ToList();

                return(MonthlyExpenses);
            }
        }
Ejemplo n.º 4
0
        public IActionResult DownloadUserData()
        {
            var user = userSessionService.GetAuthenticatedUser();

            var file = userService.DownloadUserData(user.Id);

            var contentType = "application/octet-stream";

            return(File(file.GetBytes(), contentType, "userdata.zip"));
        }
Ejemplo n.º 5
0
        public void ChangeLanguage(string language)
        {
            using (var preferencesRepository = repositoryFactory.CreatePreferencesRepository())
            {
                var user = userService.GetAuthenticatedUser();

                var userPreference = preferencesRepository.FirstOrDefault(x => x.UserId.Equals(user.Id)) ?? new Preferences();

                userPreference.Key    = LanguageKey;
                userPreference.Value  = language;
                userPreference.UserId = user.Id;

                if (userPreference.Id > 0)
                {
                    preferencesRepository.Update(userPreference);
                }
                else
                {
                    preferencesRepository.Add(userPreference);
                }

                preferencesRepository.Commit();
            }
        }
Ejemplo n.º 6
0
        public OperationResult Add(CategoryModel categoryModel)
        {
            using (var categoryRepository = repositoryFactory.CreateCategoryRepository())
            {
                var entity = categoryMapper.ToEntity(categoryModel);
                var user   = userService.GetAuthenticatedUser();
                entity.UserId = user.Id;

                categoryRepository.Add(entity);
                categoryRepository.Commit();

                return(OperationResult.Succeed());
            }
        }
Ejemplo n.º 7
0
        public AccountEvolutionModel GetAccountEvolution(int accountId)
        {
            using (var transactionRepository = repositoryFactory.CreateTransactionRepository())
            {
                var model = new AccountEvolutionModel();

                var auhtenticatedUser = userSessionService.GetAuthenticatedUser();

                var months = DateTime.Now.MonthsInYear(DateTime.Now.Month);

                var incomeTransactions = transactionRepository
                                         .Where(x => months.Any(m => x.Date.Month.Equals(m)) &&
                                                x.AccountId.Equals(accountId) && x.Account.Measurable &&
                                                x.TransactionType == TransactionType.Income)
                                         .GroupBy(x => x.Date.Month)
                                         .Select(z => z.Sum(x => x.Price.ParseNoDecimals()))
                                         .ToList();

                var outcomeTransactions = transactionRepository
                                          .Where(x => months.Any(m => x.Date.Month.Equals(m)) &&
                                                 x.AccountId.Equals(accountId) && x.Account.Measurable &&
                                                 x.TransactionType == TransactionType.Expense)
                                          .GroupBy(x => x.Date.Month)
                                          .Select(z => z.Sum(x => decimal.ToInt32(x.Price.ParseNoDecimals())))
                                          .ToList();

                model.IncomingSeries.AddRange(incomeTransactions);
                model.OutgoingSeries.AddRange(outcomeTransactions);

                var incomeMax  = model.IncomingSeries.Max();
                var outcomeMax = model.OutgoingSeries.Max();

                model.HighestValue  = incomeMax > outcomeMax ? incomeMax : outcomeMax;
                model.HighestValue += int.Parse((model.HighestValue * 0.25).ToString("F0"));

                var incomeMin  = model.IncomingSeries.Min();
                var outcomeMin = model.OutgoingSeries.Min();

                model.LowestValue = incomeMin < outcomeMin ? incomeMin : outcomeMin;

                return(model);
            }
        }
Ejemplo n.º 8
0
        public OperationResult AddReminder(ReminderModel reminderModel)
        {
            using (var reminderRepository = repositoryFactory.CreateReminderRepository())
            {
                var authenticatedUser = userService.GetAuthenticatedUser();

                var reminder = reminderMapper.ToEntity(reminderModel);

                if (reminder.UserId == 0)
                {
                    reminder.UserId = authenticatedUser.Id;
                }

                reminderRepository.Add(reminder);
                reminderRepository.Commit();

                return(OperationResult.Succeed());
            }
        }