public ActionResult Index() { var userId = User.Identity.GetUserId(); IList <Entry> entries = _entriesRepository.GetList(userId); // Calculate the total activity. decimal totalActivity = entries .Where(e => e.Exclude == false) .Sum(e => e.Duration); // Determine the number of days that have entries. int numberOfActiveDays = entries .Select(e => e.Date) .Distinct() .Count(); var viewModel = new EntriesIndexViewModel() { Entries = entries, TotalActivity = totalActivity, AverageDailyActivity = numberOfActiveDays != 0 ? (totalActivity / numberOfActiveDays) : 0 }; return(View(viewModel)); }
public async Task <IActionResult> Index(string title, string journal) { var entries = from e in _context.Entry where e.UserId == _userManager.GetUserId(User) select e; if (!string.IsNullOrEmpty(title)) { entries = entries.Where(x => x.Title.ToUpperInvariant().Contains(title.ToUpperInvariant())); } if (!string.IsNullOrEmpty(journal)) { entries = entries.Where(x => x.Journal.Equals(journal)); } var sortedEntries = await entries.ToListAsync(); sortedEntries.Sort(new EntryComparer()); var journals = from e in _context.Entry where e.UserId == _userManager.GetUserId(User) select e.Journal; var viewModel = new EntriesIndexViewModel { TitleFilter = title, JournalFilter = journal, Journals = await journals.Distinct().OrderByDescending(j => j).ToListAsync(), Entries = sortedEntries }; return(View(viewModel)); }
public async Task <IActionResult> List() { var model = new EntriesIndexViewModel { Entries = await this._api.GetAllAsync() }; return(this.View("List", model)); }
public EntriesIndexViewModel GetEntriesVM(string name) { var id = ((UserRepostiory)_repostiory).GetUserIdByName(name); var entries = _repostiory.UsersData.Where(x => x.USER_ID == id).ToList(); var userInfo = _repostiory.UserInfo.Where(x => x.USER_NAME.Equals(name)).FirstOrDefault(); var vm = new EntriesIndexViewModel(); if (userInfo != null) { vm = new EntriesIndexViewModel() { UserData = entries, RecentHeight = Convert.ToString(userInfo.RECENT_HEIGHT), RecentWeight = Convert.ToString(userInfo.RECENT_WEIGHT, CultureInfo.InvariantCulture) }; } return(vm); }