Exemple #1
0
        /// <summary>
        /// Edit action for custom reports
        /// </summary>
        /// <param name="reportId">Identifier of the report to edit</param>
        /// <returns>View with the custom report to edit</returns>
        public async Task <IActionResult> EditCustomReport(int reportId)
        {
            var allCategories = await _categoryService.GetAllCategoriesForCurrentUser();

            try
            {
                var report = await _customReportService.GetCustomReportByIdForCurrentUser(reportId);

                var availableCategories = allCategories.Select(category => new BasicCheckBoxItem
                {
                    Id      = category.Id,
                    Name    = category.Name,
                    Checked = report.Categories.Any(reportCategory => reportCategory.CategoryId == category.Id)
                }).ToList();

                return(View("UpsertCustomReport", new UpsertCustomReportModel
                {
                    AvailableCategories = availableCategories,
                    CustomReport = report
                }));
            }
            catch (NotFoundException)
            {
                TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, Resources.CustomReportNotFound);
                return(View("Home", "Index"));
            }
        }
        /// <summary>
        /// Index action for account overview
        /// </summary>
        /// <param name="bankAccountId">Id of the bank account to show</param>
        /// <returns>View containing the overview</returns>
        public async Task <IActionResult> Index(int bankAccountId)
        {
            try
            {
                var bankAccount = await _bankAccountService.GetBankAccountByIdForCurrentUser(bankAccountId);

                var transactions = await _transactionService.GetTransactionsForBankAccountForCurrentUser(bankAccountId, 200, skip : 0);

                var availableCategories = await _categoryService.GetAllCategoriesForCurrentUser();

                var model = new AccountOverviewViewModel
                {
                    Account             = bankAccount,
                    Transactions        = transactions.Take(200).ToList(),
                    AccountBalance      = bankAccount.CurrentBalance.GetValueOrDefault(),
                    AvailableCategories = availableCategories
                };

                return(View("index", model));
            }
            catch (NotFoundException)
            {
                TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, Resources.BankAccountNotFound);
                return(RedirectToAction(actionName: "Index", controllerName: "Home"));
            }
        }
        public async Task <IActionResult> UpsertTransaction(UpsertTransactionViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (model.Transaction.Id > 0)
                    {
                        await _transactionService.UpdateTransactionForCurrentUser(model.Transaction);

                        return(Json(new SinanceJsonResult
                        {
                            Success = true
                        }));
                    }
                    else
                    {
                        await _transactionService.CreateTransactionForCurrentUser(model.Transaction);

                        return(Json(new SinanceJsonResult
                        {
                            Success = true
                        }));
                    }
                }
                catch (NotFoundException)
                {
                    TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, Resources.BankAccountNotFound);
                }
            }

            return(PartialView("UpsertTransactionPartial", model));
        }
Exemple #4
0
        public async Task <IActionResult> SaveImport(ImportModel model)
        {
            try
            {
                var(skippedTransactions, savedTransactions) = await _importService.SaveImport(model);

                var message = string.Format(CultureInfo.CurrentCulture, Resources.TransactionsAddedAndSkippedFormat, savedTransactions, skippedTransactions);

                TempDataHelper.SetTemporaryMessage(tempData: TempData,
                                                   state: savedTransactions != 0 ? MessageState.Success : MessageState.Warning,
                                                   message: message);
                return(RedirectToAction("Index", "AccountOverview", new { @bankAccountId = model.BankAccountId }));
            }
            catch (NotFoundException exc)
            {
                if (exc.ItemName == nameof(ImportModel))
                {
                    TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, Resources.ImportTimeOut);
                }
                else
                {
                    TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, Resources.BankAccountNotFound);
                }
                return(RedirectToAction("Index", "Home"));
            }
        }
Exemple #5
0
        public async Task <IActionResult> Import(IFormFile file, ImportModel model)
        {
            try
            {
                using var stream = file.OpenReadStream();

                await _importService.CreateImportPreview(stream, model);

                return(View("ImportResult", model));
            }
            catch (NotFoundException exc)
            {
                Log.Error(exc, "Exception during Import");

                TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, message: Resources.BankAccountNotFound);
                return(RedirectToAction("Index"));
            }
            catch (ImportFileException exc)
            {
                Log.Error(exc, "Exception during Import");

                TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, message: Resources.ErrorWhileProcessingImport);
                return(RedirectToAction("Index"));
            }
            catch (Exception exc)
            {
                Log.Error(exc, "Exception during Import");

                TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, message: Resources.Error);
                return(RedirectToAction("Index"));
            }
        }
        /// <summary>
        /// Starts the edit action for a model
        /// </summary>
        /// <param name="transactionId">Id of the model to edit</param>
        /// <returns>Partial view for editing the model</returns>
        public async Task <IActionResult> EditTransaction(int transactionId)
        {
            try
            {
                var transaction = await _transactionService.GetTransactionByIdForCurrentUser(transactionId);

                var userCategories = await _categoryService.GetAllCategoriesForCurrentUser();

                var availableCategories = CreateAvailableCategoriesSelectList(userCategories);

                var model = new UpsertTransactionViewModel
                {
                    AvailableCategories = availableCategories,
                    Transaction         = transaction
                };

                return(PartialView("UpsertTransactionPartial", model));
            }
            catch (NotFoundException)
            {
                TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, Resources.TransactionNotFound);
            }

            return(View("Index"));
        }
Exemple #7
0
        /// <summary>
        /// Upserts a category mapping to the database
        /// </summary>
        /// <param name="model">Model to upsert</param>
        /// <returns>Result of the upsert</returns>
        public async Task <IActionResult> UpsertCategoryMapping(CategoryMappingModel model)
        {
            if (ModelState.IsValid)
            {
                // Placeholder extra validation, in the future all mappings should be possible
                if (model.ColumnTypeId != ColumnType.Description &&
                    model.ColumnTypeId != ColumnType.Name &&
                    model.ColumnTypeId != ColumnType.DestinationAccount)
                {
                    ModelState.AddModelError("", Resources.UnsupportedColumnTypeMapping);
                    return(PartialView("UpsertCategoryMapping", model));
                }

                if (model.Id > 0)
                {
                    try
                    {
                        await _categoryMappingService.UpdateCategoryMappingForCurrentUser(model);

                        return(Json(new SinanceJsonResult
                        {
                            Success = true
                        }));
                    }
                    catch (NotFoundException)
                    {
                        TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, Resources.CategoryMappingNotFound);
                        return(PartialView("UpsertCategoryMapping", model));
                    }
                }
                else
                {
                    try
                    {
                        await _categoryMappingService.CreateCategoryMappingForCurrentUser(model);

                        return(Json(new SinanceJsonResult
                        {
                            Success = true
                        }));
                    }
                    catch (NotFoundException)
                    {
                        TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, Resources.CategoryNotFound);
                        return(PartialView("UpsertCategoryMapping", model));
                    }
                }
            }

            return(PartialView("UpsertCategoryMapping", model));
        }
        /// <summary>
        /// Start an edit account action
        /// </summary>
        /// <param name="accountId">Id of account to edit</param>
        /// <returns>Actionresult with details of the account</returns>
        public async Task <IActionResult> EditAccount(int accountId)
        {
            try
            {
                var bankAccount = await _bankAccountService.GetBankAccountByIdForCurrentUser(accountId);

                return(View("UpsertAccount", bankAccount));
            }
            catch (NotFoundException)
            {
                TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, Resources.BankAccountNotFound);
                return(RedirectToAction("Index"));
            }
        }
Exemple #9
0
        /// <summary>
        /// Starts the process of editing a category mapping
        /// </summary>
        /// <param name="categoryMappingId">Category mapping to edit</param>
        /// <returns>Partial view to edit the mapping</returns>
        public async Task <IActionResult> EditCategoryMapping(int categoryMappingId)
        {
            try
            {
                var model = await _categoryMappingService.GetCategoryMappingByIdForCurrentUser(categoryMappingId);

                return(PartialView("UpsertCategoryMapping", model));
            }
            catch (NotFoundException)
            {
                TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, Resources.CategoryMappingNotFound);
                return(View("Index"));
            }
        }
        /// <summary>
        /// Removes the given account
        /// </summary>
        /// <param name="accountId">Id of account to remove</param>
        /// <returns>ActionResult with details of the remove action</returns>
        public async Task <IActionResult> RemoveAccount(int accountId)
        {
            try
            {
                await _bankAccountService.DeleteBankAccountByIdForCurrentUser(accountId);

                TempDataHelper.SetTemporaryMessage(TempData, MessageState.Success, Resources.BankAccountRemoved);
            }
            catch (NotFoundException)
            {
                TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, Resources.BankAccountNotFound);
            }

            return(RedirectToAction("Index"));
        }
        /// <summary>
        /// Deletes a model
        /// </summary>
        /// <param name="transactionId">Id of model to delete</param>
        /// <returns>Result of the delete action</returns>
        public async Task <IActionResult> DeleteTransaction(int transactionId, int bankAccountId)
        {
            try
            {
                await _transactionService.DeleteTransactionForCurrentUser(transactionId);

                TempDataHelper.SetTemporaryMessage(TempData, MessageState.Success, Resources.TransactionDeleted);
                return(RedirectToAction("Index", new { bankAccountId }));
            }
            catch (NotFoundException)
            {
                TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, Resources.TransactionNotFound);
                return(RedirectToAction("Index", "Home"));
            }
        }
Exemple #12
0
        /// <summary>
        /// Removes a category mapping from the database
        /// </summary>
        /// <param name="categoryMappingId">Id of the mapping to remove</param>
        /// <returns>Redirect to the edit category view</returns>
        public async Task <IActionResult> RemoveCategoryMapping(int categoryMappingId, int categoryId)
        {
            try
            {
                await _categoryMappingService.DeleteCategoryMappingByIdForCurrentUser(categoryMappingId);

                TempDataHelper.SetTemporaryMessage(TempData, MessageState.Success, Resources.CategoryMappingDeleted);
                return(RedirectToAction("EditCategory", "Category", new { categoryId }));
            }
            catch (NotFoundException)
            {
                TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, Resources.CategoryMappingNotFound);
                return(RedirectToAction("Index", "Category"));
            }
        }
Exemple #13
0
        /// <summary>
        /// Assigns the category to the previously previewed transactions
        /// </summary>
        /// <param name="categoryId">Id of the category to assign</param>
        /// <returns>Redirect to the edit category action</returns>
        public async Task <IActionResult> UpdateCategoryToMappedTransactions(int categoryId, IEnumerable <int> transactionIds)
        {
            try
            {
                await _categoryService.MapCategoryToTransactionsForCurrentUser(categoryId, transactionIds);

                TempDataHelper.SetTemporaryMessage(TempData, MessageState.Success, Resources.CategoryMappingsAppliedToTransactions);

                return(RedirectToAction("EditCategory", new { categoryId }));
            }
            catch (NotFoundException)
            {
                TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, Resources.CategoryNotFound);
                return(RedirectToAction("Index"));
            }
        }
Exemple #14
0
        /// <summary>
        /// Starts the add process for a new categorymapping
        /// </summary>
        /// <param name="categoryId">Id of the category to add the mapping to</param>
        /// <returns>Partial view for adding the mapping</returns>
        public async Task <IActionResult> AddCategoryMapping(int categoryId)
        {
            try
            {
                var categoryModel = await _categoryService.GetCategoryByIdForCurrentUser(categoryId);

                return(PartialView("UpsertCategoryMapping", new CategoryMappingModel
                {
                    CategoryName = categoryModel.Name,
                    CategoryId = categoryModel.Id
                }));
            }
            catch (NotFoundException)
            {
                TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, Resources.CategoryNotFound);
                return(View("Index"));
            }
        }
Exemple #15
0
        /// <summary>
        /// Removes the given category from the database
        /// </summary>
        /// <param name="categoryId">Id of category to remove</param>
        /// <returns>Index page</returns>
        public async Task <IActionResult> RemoveCategory(int categoryId)
        {
            try
            {
                await _categoryService.DeleteCategoryByIdForCurrentUser(categoryId);

                TempDataHelper.SetTemporaryMessage(TempData, MessageState.Success, Resources.CategoryRemoved);
            }
            catch (NotFoundException)
            {
                TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, Resources.CategoryNotFound);
            }
            catch (DeleteStandardCategoryException)
            {
                TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, Resources.DeleteStandardCategoryExceptionMessage);
            }

            return(RedirectToAction("Index"));
        }
Exemple #16
0
        /// <summary>
        /// Upserts the category model to the database
        /// </summary>
        /// <param name="model">Model to upsert</param>
        /// <returns>Index page and message if success</returns>
        public async Task <IActionResult> UpsertCategory(UpsertCategoryModel model)
        {
            if (model.CategoryModel.Id > 0)
            {
                if (!ModelState.IsValid)
                {
                    return(RedirectToAction("EditCategory", new { model.CategoryModel.Id }));
                }

                try
                {
                    await _categoryService.UpdateCategoryForCurrentUser(model.CategoryModel);

                    TempDataHelper.SetTemporaryMessage(TempData, MessageState.Success, Resources.CategoryUpdated);
                }
                catch (NotFoundException)
                {
                    TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, Resources.CategoryNotFound);
                }
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    return(RedirectToAction("AddCategory"));
                }

                try
                {
                    await _categoryService.CreateCategoryForCurrentUser(model.CategoryModel);

                    TempDataHelper.SetTemporaryMessage(TempData, MessageState.Success, Resources.CategoryCreated);
                }
                catch (AlreadyExistsException)
                {
                    TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, string.Format(Resources.CategoryAlreadyExists, model.CategoryModel.Name));
                }
            }

            return(RedirectToAction("Index"));
        }
        /// <summary>
        /// Upserts an account
        /// </summary>
        /// <param name="model">Model to use for upsert</param>
        /// <returns>ActionResult with the outcome</returns>
        public async Task <IActionResult> UpsertAccount(BankAccountModel model)
        {
            ActionResult result = View(model);

            if (ModelState.IsValid)
            {
                try
                {
                    if (model.Id > 0)
                    {
                        await _bankAccountService.UpdateBankAccountForCurrentUser(model);

                        TempDataHelper.SetTemporaryMessage(TempData, MessageState.Success, Resources.BankAccountCreated);
                    }
                    else
                    {
                        await _bankAccountService.CreateBankAccountForCurrentUser(model);

                        TempDataHelper.SetTemporaryMessage(TempData, MessageState.Success, Resources.BankAccountUpdated);
                    }
                }
                catch (NotFoundException)
                {
                    ModelState.AddModelError("Message", Resources.BankAccountNotFound);
                }
                catch (AlreadyExistsException)
                {
                    ModelState.AddModelError("Message", Resources.BankAccountNotFound);
                }
                catch (ArgumentException exc)
                {
                    ModelState.AddModelError("Message", exc.Message);
                }

                return(RedirectToAction("Index"));
            }

            return(result);
        }
Exemple #18
0
        /// <summary>
        /// Provides an actionresult for editing a new category
        /// </summary>
        /// <param name="categoryId">Id of category to edit</param>
        /// <param name="includeTransactions">Include transactions or not for overview</param>
        /// <returns>Actionresult for editing a new category</returns>
        public async Task <IActionResult> EditCategory(int categoryId)
        {
            try
            {
                var category = await _categoryService.GetCategoryByIdForCurrentUser(categoryId);

                var availableParentCategories = await CreateAvailableParentCategoriesSelectList(category);

                var model = new UpsertCategoryModel
                {
                    CategoryModel             = category,
                    AvailableParentCategories = availableParentCategories
                };

                return(View("UpsertCategory", model));
            }
            catch (NotFoundException)
            {
                TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, Resources.CategoryNotFound);
                return(RedirectToAction("Index"));
            }
        }
Exemple #19
0
        /// <summary>
        /// Upserts a custom report to the database
        /// </summary>
        /// <param name="model">Model to upsert</param>
        /// <returns>Redirect to the upserted custom report</returns>
        public async Task <IActionResult> UpsertCustomReport(UpsertCustomReportModel model)
        {
            if (!ModelState.IsValid)
            {
                TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, Resources.Error);
            }

            if (model.CustomReport.Id > 0)
            {
                try
                {
                    model.CustomReport.Categories = model.AvailableCategories.Where(x => x.Checked).Select(x => new CustomReportCategoryModel
                    {
                        CategoryId = x.Id
                    }).ToList();

                    await _customReportService.UpdateCustomReport(model.CustomReport);
                }
                catch (NotFoundException)
                {
                    TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, Resources.CustomReportNotFound);
                    return(View("Home", "Index"));
                }
            }
            else
            {
                model.CustomReport.Categories = model.AvailableCategories.Where(x => x.Checked).Select(x => new CustomReportCategoryModel
                {
                    CategoryId = x.Id
                }).ToList();

                await _customReportService.CreateCustomReport(model.CustomReport);
            }

            return(RedirectToAction("CustomReport", new { reportId = model.CustomReport.Id }));
        }