Exemple #1
0
        public ActionResult About(bool userCheck,Event fact)
        {
            using (EntityContext db = new EntityContext())
            {
                User user = db.Users.Find(WebSecurity.GetUserId(User.Identity.Name));
                var eventToCheck = db.Events
                 .Where(i => i.EventId == fact.EventId)
                 .Single();

                if (userCheck == false)
                {
                    eventToCheck.Users.Add(user);
                    user.Rating++;
                }
                else
                {
                    eventToCheck.Users.Remove(user);
                    user.Rating--;

                }
                db.SaveChanges();
            }
            return RedirectToAction("About", new { id = fact.EventId });
        }
Exemple #2
0
        public ActionResult Create(Event fact, string[] selectedInterests)
        {
            if (ModelState.IsValid)
            {
                using (EntityContext db = new EntityContext())
                {
                    db.Events.Add(fact);
                    db.SaveChanges();
                }
                using (EntityContext db = new EntityContext())
                {
                    var userToUpdate = db.Events
                 .Where(i => i.EventId == fact.EventId)
                 .Single();
                    var selectedInterestsHs = new HashSet<string>(selectedInterests);
                    foreach (var interest in db.Interests)
                    {
                        if (selectedInterestsHs.Contains(interest.InterestId.ToString()))
                        {

                            userToUpdate.Interests.Add(interest);

                        }
                    }

                    db.SaveChanges();
                }
                return RedirectToAction("Index");
            }

            return View();
        }