public ActionResult Show(int calendarId) { var userId = Guid.Parse(HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId()); var calendar = _calendarRepository.GetCalendarByCalendarId(calendarId); string check = "inherit"; if (calendar.OwnerId == userId) { check = "none"; } ViewBag.UserCheck = check; ViewBag.CalendarName = calendar.Name; ViewBag.CalendarId = calendar.CalendarId; ViewBag.UserId = calendar.OwnerId.ToString(); ViewBag.OwnerName = _userRepository.GetUserByID(calendar.OwnerId).FirstName + " " + _userRepository.GetUserByID(calendar.OwnerId).LastName; ViewBag.DisplayAll = User.Identity.GetUserId().Equals(calendar.OwnerId.ToString()); ViewBag.IsOwner = calendar.OwnerId == userId; var flag = _subscriptionRepository.SubscriptionContainsInUserList(calendarId, userId); if (flag == true) { ViewBag.Flag = "deabonnieren"; } else { ViewBag.Flag = "abonnieren"; } return(View()); }
// Methods // GET: Subscription public ActionResult Index() { var userId = Guid.Parse(HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId()); var subs = _subscriptionRepository.GetAllSubscriptionsByUserId(userId); var subUsers = new List <User>(); var subCalendars = new List <Calendar>(); foreach (Calendar_Subscription cs in subs) { if (subUsers.Contains(_userRepository.GetUserByID(_calendarRepository.GetUserByCalendarId(cs.CalendarId))) == false) { subUsers.Add(_userRepository.GetUserByID(_calendarRepository.GetUserByCalendarId(cs.CalendarId))); } subCalendars.Add(_calendarRepository.GetCalendarByCalendarId(cs.CalendarId)); } ViewBag.SubsUsers = subUsers; var subsByUser = new List <SubscriptionModel>(); foreach (User u in subUsers) { var userFullName = u.FirstName + " " + u.LastName; var calendars = new List <Calendar>(); foreach (Calendar c in subCalendars) { if (u.UserId == c.OwnerId) { calendars.Add(c); } } subsByUser.Add(new SubscriptionModel { FullName = userFullName, Subscriptions = calendars }); } ViewBag.Result = subsByUser; return(View()); }