public ActionResult Challenge(ChallengeEvent model) { List <UserChallenges> userChallengesList = new List <UserChallenges>(); List <Notifications> notificationsList = new List <Notifications>(); userChallengesList = _challengeService.QueryableCustom().Where(w => w.EventId == model.EventId && w.IsActive).ToList(); if (model.SelectedIds.Count() > 0) { foreach (var item in userChallengesList) { item.IsActive = false; item.ObjectState = ObjectState.Modified; _challengeService.InsertOrUpdateGraph(item); _unitOfWork.SaveChanges(); } //eventid for (int i = 0; i < model.SelectedIds.Length; i++) { UserChallenges userChallenge = new UserChallenges(); userChallenge.EventId = model.EventId; userChallenge.IsActive = true; userChallenge.IsAccepted = false; userChallenge.UserId = Common.CurrentUser.Id; userChallenge.DateCreated = DateTime.Now; userChallenge.ToChallengeId = model.SelectedIds[i]; //userChallengesList.Add(); _challengeService.Insert(userChallenge); } saveResult = _unitOfWork.SaveChanges(); for (int i = 0; i < model.SelectedIds.Length; i++) { Notifications notification = new Notifications(); notification.ObjectState = ObjectState.Added; notification.Notification = Common.CurrentUser.Name + " Challenged you for the event " + model.EventName; notification.Link = "/Events/Detail/" + model.EventId; notification.IsRead = false; notification.Icon = "fa fa-plus-square fa-lg"; notification.UserId = model.SelectedIds[i]; notification.NotificationDate = DateTime.Now; notification.ProfilePic = Common.CurrentUser.ProfilePic == null ? "/assets/images/avatar-1.png" : Common.CurrentUser.ProfilePic; notificationsList.Add(notification); } NotificationHub.SendNotification(model.SelectedIds.ToList(), " You are challenged for event " + model.EventName, "fa fa-plus-square fa-lg", "/Events/Info/" + model.EventId, Common.CurrentUser.ProfilePic == null ? "/assets/images/avatar-1.png" : Common.CurrentUser.ProfilePic); _notificationsService.InsertGraphRange(notificationsList); _unitOfWork.SaveChanges(); } return(RedirectToAction("Index")); }