public async Task <IActionResult> DateSorted(DateTime startDate, DateTime endDate, int categoryId, int page = 1) { try { var user = await this.userManager.GetUserAsync(this.User); if (!await this.categoriesService.IsUserOwnCategoryAsync(user.Id, categoryId)) { return(this.Redirect($"/Home/Error?message={GlobalConstants.NoPermissionForViewOrEditCategory}")); } var category = await this.categoriesService.GetRecordsByDateRangeAsync(startDate, endDate, categoryId, page, ItemsPerPage); CategoryRecordsViewModel model = new CategoryRecordsViewModel() { Records = category.Records .Select(r => new RecordsByCategoryViewModel { Amount = r.Amount, CreatedOn = r.CreatedOn.ToString("dddd, dd MMMM yyyy", CultureInfo.InvariantCulture), Description = r.Description, Id = r.Id, Type = Enum.Parse <RecordTypeInputModel>(r.Type.ToString()), }) .ToList(), Category = category.Category, CategoryId = categoryId, Currency = category.Currency, WalletId = category.WalletId, WalletName = category.WalletName, BadgeColor = Enum.Parse <BadgeColor>(category.BadgeColor.ToString()), }; 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; model.ItemsPerPage = ItemsPerPage; model.PageNumber = page; model.RecordsCount = this.categoriesService.GetDateSortedRecordsCount(startDate, endDate, categoryId); return(this.View(model)); } catch (Exception ex) { return(this.Redirect($"/Home/Error?message={ex.Message}")); } }
public async Task <IActionResult> Search(int categoryId, string searchTerm, int page = 1) { try { var user = await this.userManager.GetUserAsync(this.User); if (!await this.categoriesService.IsUserOwnCategoryAsync(user.Id, categoryId)) { return(this.Redirect($"/Home/Error?message={GlobalConstants.NoPermissionForViewOrEditCategory}")); } if (searchTerm == null) { searchTerm = string.Empty; } var category = await this.categoriesService.GetRecordsByKeywordAsync(searchTerm, categoryId, page, ItemsPerPage); CategoryRecordsViewModel model = new CategoryRecordsViewModel() { Records = category.Records .Select(r => new RecordsByCategoryViewModel { Amount = r.Amount, CreatedOn = r.CreatedOn.ToString("dddd, dd MMMM yyyy", CultureInfo.InvariantCulture), Description = r.Description, Id = r.Id, Type = Enum.Parse <RecordTypeInputModel>(r.Type.ToString()), }) .ToList(), Category = category.Category, CategoryId = categoryId, Currency = category.Currency, WalletId = category.WalletId, WalletName = category.WalletName, BadgeColor = Enum.Parse <BadgeColor>(category.BadgeColor.ToString()), SearchTerm = searchTerm, }; model.ItemsPerPage = ItemsPerPage; model.PageNumber = page; model.RecordsCount = this.categoriesService.GetSearchRecordsCount(searchTerm, categoryId); return(this.View(model)); } catch (Exception ex) { return(this.Redirect($"/Home/Error?message={ex.Message}")); } }