public async Task <IActionResult> DateSorted(DateTime startDate, DateTime endDate, int id, int page = 1) { try { var user = await this.userManager.GetUserAsync(this.User); if (!await this.walletsService.IsUserOwnWalletAsync(user.Id, id)) { return(this.Redirect($"/Home/Error?message={GlobalConstants.NoPermissionForEditWallet}")); } var model = new WalletSearchResultViewModel(); model.ItemsPerPage = ItemsPerPage; model.PageNumber = page; var records = await this.walletsService.GetRecordsByDateRangeAsync(startDate, endDate, id, page, ItemsPerPage); model.Records = records.Select(r => new WalletSearchResultSingleRecordViewModel { Amount = r.Amount, Category = r.Category, CategoryId = r.CategoryId, CreatedOn = r.CreatedOn.ToString("dddd, dd MMMM yyyy", CultureInfo.InvariantCulture), Description = r.Description, Wallet = r.Wallet, Id = r.Id, Type = Enum.Parse <RecordTypeInputModel>(r.Type.ToString()), Currency = r.Currency, BadgeColor = Enum.Parse <BadgeColor>(r.BadgeColor.ToString()), }) .ToList(); model.RecordsCount = this.walletsService.GetDateSortedRecordsCount(startDate, endDate, id); model.WalletId = id; model.Wallet = await this.walletsService.GetWalletNameAsync(id); var startDate12AM = new DateTime(startDate.Year, startDate.Month, startDate.Day, 0, 0, 0); var endDate12PM = new DateTime(endDate.Year, endDate.Month, endDate.Day, 23, 59, 59); model.StartDate = startDate12AM; model.EndDate = endDate12PM; return(this.View(model)); } catch (Exception ex) { return(this.Redirect($"/Home/Error?message={ex.Message}")); } }
public async Task <IActionResult> Search(int id, string searchTerm, int page = 1) { try { var user = await this.userManager.GetUserAsync(this.User); if (!await this.walletsService.IsUserOwnWalletAsync(user.Id, id)) { return(this.Redirect($"/Home/Error?message={GlobalConstants.NoPermissionForEditWallet}")); } if (searchTerm == null) { searchTerm = string.Empty; } var model = new WalletSearchResultViewModel(); model.ItemsPerPage = ItemsPerPage; model.PageNumber = page; var records = await this.walletsService.GetRecordsByKeywordAsync(searchTerm, id, page, ItemsPerPage); model.Records = records.Select(r => new WalletSearchResultSingleRecordViewModel { Amount = r.Amount, Category = r.Category, CategoryId = r.CategoryId, CreatedOn = r.CreatedOn.ToString("D", CultureInfo.InvariantCulture), Description = r.Description, Wallet = r.Wallet, Id = r.Id, Type = Enum.Parse <RecordTypeInputModel>(r.Type.ToString()), Currency = r.Currency, BadgeColor = Enum.Parse <BadgeColor>(r.BadgeColor.ToString()), }) .ToList(); model.RecordsCount = this.walletsService.GetSearchRecordsCount(searchTerm, id); model.SearchTerm = searchTerm; model.WalletId = id; model.Wallet = await this.walletsService.GetWalletNameAsync(id); return(this.View(model)); } catch (Exception ex) { return(this.Redirect($"/Home/Error?message={ex.Message}")); } }