public ActionResult CreateTip(TipOfWeek newTip) { try { // TODO: Add insert logic here var customers = _context.Customers.ToList(); foreach (var item in customers) { Notification notification = new Notification(); notification.Id = item.IdentityUserId; notification.notificationInfo = "A new Matrix90 has been added."; notification.controllerAction = "Matrix90Tips"; _context.Notifications.Add(notification); _context.SaveChanges(); } newTip.uploadDate = DateTime.Now; _context.TipOfWeeks.Add(newTip); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public async Task <IActionResult> Favorites() { Customer current = _context.Customers.Where(c => c.IdentityUserId == User.FindFirstValue(ClaimTypes.NameIdentifier)).SingleOrDefault(); List <FavoriteTip> favoriteTips = _context.FavoriteTips.Where(t => t.CustomerId == current.CustomerId).ToList(); List <TipOfWeek> tips = new List <TipOfWeek>(); foreach (var item in favoriteTips) { TipOfWeek tip = _context.TipOfWeeks.Where(t => t.TipOfWeekId == item.TipOfWeekId).SingleOrDefault(); if (tip != null) { tips.Add(tip); } } return(View(tips)); }