public IActionResult MainPage(string id)
        {
            var userID = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            var listDate = string.IsNullOrWhiteSpace(id)
                ? DateTime.Now
                : DateTime.ParseExact(id, "MMyyyy", CultureInfo.InvariantCulture, DateTimeStyles.None);

            _autoOperationsService.ExecuteMonthlyOperations(userID);

            var viewModel = new MainPageViewModel()
            {
                DefaultCurrency = _accountService.GetUserDefaultCurrencySymbol(userID),
                ListDate        = listDate.ToString("Y", new CultureInfo("ru-RU")),
                GoalsList       = _goalService.GetUserGoals(userID)
            };

            return(View(viewModel));
        }
Exemple #2
0
        public async Task <IActionResult> Login([FromBody] LoginRequestDTO model)
        {
            try
            {
                int statusCode = 200;

                var result = await _signInManager.PasswordSignInAsync(model.usr, model.pass, true, lockoutOnFailure : false);

                var userID = _accountService.GetUserIDByName(model.usr);

                if (result.Succeeded)
                {
                    _autoOperationsService.ExecuteMonthlyOperations(userID);
                    var userConfigs = _accountService.GetUserConfigs(userID);

                    var categories     = _categoryService.GetAllUserCategories(userID);
                    var categoriesList = new List <CategoryDTO>();
                    foreach (var item in categories)
                    {
                        categoriesList.Add(new CategoryDTO
                        {
                            Id   = item.ID,
                            Name = item.Name,
                            IsSpendingCategory = item.IsSpendingCategory,
                            IsSystem           = item.IsSystem,
                            CreatedBy          = item.CreatedByID, //TODO check
                            Icon = item.Icon
                        });
                    }

                    var transactions     = _transactionService.GetUserTransactions(userID, DateTime.Now.Year, DateTime.Now.Month);
                    var transactionsList = new List <TransactionListItem>();
                    foreach (var transaction in transactions)
                    {
                        TransactionListItem listItem = new TransactionListItem()
                        {
                            Id         = transaction.ID.ToString(),
                            Amount     = transaction.Amount,
                            CategoryId = transaction.CategoryID,
                            IsPlaned   = transaction.IsPlaned,
                            IsSpending = transaction.IsSpending,
                            Name       = transaction.Name,
                            TransDate  = transaction.TransactionDate,
                            UserId     = transaction.UserID
                        };
                        transactionsList.Add(listItem);
                    }

                    LoginResponseDTO response = new LoginResponseDTO
                    {
                        Status       = statusCode,
                        UserSettings = userConfigs,
                        Categories   = categoriesList,
                        Transactions = transactionsList
                    };

                    return(Ok(response));
                }
                else
                {
                    statusCode = 401;
                    LoginResponseDTO erroResult = new LoginResponseDTO
                    {
                        Status = 401
                    };
                    return(Ok(erroResult));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }