public PartialViewResult SaveUserDeviceData(List <string[]> deviceList) { var _db = new ApplicationDbContext(); var user = _db.Users.SingleOrDefault(u => u.UserName.Equals(User.Identity.Name)); if (user != null) { foreach (string[] device in deviceList) { if (device[1].Equals("true")) { user.Devices.SingleOrDefault(d => d.Id.ToString().Equals(device[0])).IsActive = true; } else { user.Devices.SingleOrDefault(d => d.Id.ToString().Equals(device[0])).IsActive = false; } } _db.SaveChanges(); } var model = new UserProfileViewModel(); model.UserDevices = new List <UserDeviceViewModel>(); foreach (UserDevice d in user.Devices) { UserDeviceViewModel userDevice = new UserDeviceViewModel { DeviceName = d.DeviceName, Activated = d.IsActive, Id = d.Id.ToString(), UserId = d.User.Id.ToString() }; model.UserDevices.Add(userDevice); } return(PartialView("_UserDevices", model)); }
/// <summary> /// /// </summary> /// <returns></returns> public ActionResult Index() { var model = new UserProfileViewModel(); var user = AppUser; model.Profile = new ProfileViewModel { FirstName = user.FirstName, LastName = user.LastName, }; var semester = SemesterService.GetSemester(DateTime.Today); var subscription = Db.Subscriptions.OfType <SemesterSubscription>().SingleOrDefault(x => x.UserId.Equals(user.Id) && x.SemesterGroup.Semester.Id == semester.Id); if (subscription != null) { model.SemesterProfile = new UserSemesterViewModel { Faculty = subscription.SemesterGroup.CapacityGroup.CurriculumGroup.Curriculum.Organiser.ShortName, Curriculum = subscription.SemesterGroup.CapacityGroup.CurriculumGroup.Curriculum.ShortName, Group = subscription.SemesterGroup.Id.ToString() }; model.SemesterGroup = subscription.SemesterGroup; } else { model.SemesterProfile = new UserSemesterViewModel { Faculty = string.Empty, Curriculum = string.Empty, Group = string.Empty }; } model.MsgProfile = new UserMsgProfileViewModel { LikeEmailOnGlobalLevel = user.LikeEMails, }; model.MemberState = user.MemberState; //model.Semester = semester; //notification Section Daten abrufen model.UserDevices = new List <UserDeviceViewModel>(); foreach (UserDevice d in user.Devices) { UserDeviceViewModel userDevice = new UserDeviceViewModel { DeviceName = d.DeviceName, Activated = d.IsActive, Id = d.Id.ToString(), UserId = d.User.Id.ToString() }; switch (d.Platform) { case DevicePlatform.Android: userDevice.DeviceName = "Android"; break; case DevicePlatform.IOS: userDevice.DeviceName = "iOS"; break; case DevicePlatform.WinPhone: userDevice.DeviceName = "Windows Phone"; break; } model.UserDevices.Add(userDevice); } //InitSelectionLists(user); ViewBag.CalendarToken = user.Id; ViewBag.CalendarPeriod = SemesterService.GetSemester(DateTime.Today).Name; return(View(model)); }