public RedirectToActionResult Join(CreatedEvent ce) { var entity = repository.CreatedEvents .Where(e => e.ID == ce.ID) .FirstOrDefault(); if (entity != null) { if (p_rope.participations.Where(p => p.CreatedEvent == entity) .Where(c => c.Username == User.Identity.Name).Count() == 0) { var participate = new Participation() { CreatedEvent = entity, Title = entity.Title, StudentNumber = User.Identity.Name, Date = entity.Date, Username = User.Identity.Name, Location = entity.Location }; p_rope.SaveEvent(participate); var dbEntity = repository.CreatedEvents.Where(e => e.ID == ce.ID).FirstOrDefault(); dbEntity.CountOfParticipation += 1; repository.SaveEvent(dbEntity); } else { // ViewBag.Message = string.Format("You have joined this activity!"); // TempData["message_join"]="You have joined this activity!"; TempData["ID"] = entity.ID.ToString(); } } return(RedirectToAction("Index")); }