예제 #1
0
        public ActionResult SearchFilter(string search, bool members = true, bool meetings = true, bool oldMeetings = true)
        {
            search = search.ToUpper();
            SearchResult sr = new SearchResult();

            using (var ctx = new KlubbdatabasEntities2())
            {
                ctx.Configuration.ProxyCreationEnabled = false;
                if (meetings)
                {
                    sr.Meetings = ctx.GameLocations.Include(x => x.MeetingParticipants).ToList();
                    if (!oldMeetings)
                    {
                        sr.Meetings = sr.Meetings.Where(x => x.IsUpcoming).ToList();
                    }
                }
                if (members)
                {
                    sr.Members = ctx.Personers.ToList();
                }
            }
            if (!string.IsNullOrEmpty(search))
            {
                if (meetings)
                {
                    sr.Meetings = sr.Meetings.Where(x => x.Adress.ToUpper().Contains(search)).ToList();
                }
                if (members)
                {
                    sr.Members = sr.Members.Where(x => x.Namn.ToUpper().Contains(search) || x.Adress.ToUpper().Contains(search)).ToList();
                }
            }
            return(PartialView("~/Views/Shared/_SearchFilter.cshtml", sr));
        }
예제 #2
0
        public ActionResult DeleteMeeting(int id)
        {
            GameLocation meeting;

            using (var ctx = new KlubbdatabasEntities2())
            {
                meeting = ctx.GameLocations.Where(x => x.ID == id).FirstOrDefault();
            }
            return(View(meeting));
        }
예제 #3
0
        public ActionResult EditMeeting(int id)
        {
            GameLocation meeting;

            using (var ctx = new KlubbdatabasEntities2())
            {
                meeting = (GameLocation)ctx.GameLocations.Where(x => x.ID == id).Include("MeetingParticipants.Personer").FirstOrDefault();
            }
            return(View(meeting));
        }
예제 #4
0
 public ActionResult DeleteMeeting(GameLocation meeting)
 {
     using (var ctx = new KlubbdatabasEntities2())
     {
         var model = ctx.GameLocations.Find(meeting.ID);
         ctx.GameLocations.Remove(model);
         ctx.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
예제 #5
0
        public ActionResult DeleteMember(int id)
        {
            Personer person;

            using (var ctx = new KlubbdatabasEntities2())
            {
                person = ctx.Personers.Where(x => x.ID == id).FirstOrDefault();
            }
            return(View(person));
        }
예제 #6
0
 public ActionResult DeleteMember(Personer person)
 {
     using (var ctx = new KlubbdatabasEntities2())
     {
         var model = ctx.Personers.Find(person.ID);
         model.Active = false;
         ctx.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
예제 #7
0
        public ActionResult NewMeeting()
        {
            GameLocation model = new GameLocation();

            using (var ctx = new KlubbdatabasEntities2())
            {
                model.ID = ctx.GameLocations.Max(x => x.ID) + 1;
            }

            return(View(model));
        }
예제 #8
0
        public ActionResult GetAvaibleMembers(int meetingId)
        {
            AddMember model = new AddMember();

            model.CurrentMeetingId = meetingId;
            using (var ctx = new KlubbdatabasEntities2())
            {
                model.AvailableMembers = ctx.Personers.Where(x => x.MeetingParticipants.All(y => y.GameLocationId != meetingId)).Where(z => z.Active).ToList();
            }

            return(PartialView("~/Views/Shared/_Members.cshtml", model));
        }
예제 #9
0
        public ActionResult Index()
        {
            SearchResult sr = new SearchResult();

            using (var ctx = new KlubbdatabasEntities2())
            {
                sr.Meetings = ctx.GameLocations.Include(x => x.MeetingParticipants).ToList();
                sr.Members  = ctx.Personers.ToList();
            }

            return(View(sr));
        }
예제 #10
0
 public ActionResult AddMember(Personer person)
 {
     if (!ModelState.IsValid)
     {
         return(View(person));
     }
     using (var ctx = new KlubbdatabasEntities2())
     {
         ctx.Personers.Add(person);
         ctx.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
예제 #11
0
        public ActionResult EditMeeting(GameLocation meeting)
        {
            using (var ctx = new KlubbdatabasEntities2())
            {
                var model = ctx.GameLocations.Find(meeting.ID);

                if (TryUpdateModel(model))
                {
                    ctx.SaveChanges();
                }
            }
            return(RedirectToAction("Index"));
        }
예제 #12
0
 public ActionResult NewMeeting(GameLocation meeting)
 {
     if (!ModelState.IsValid)
     {
         return(View(meeting));
     }
     using (var ctx = new KlubbdatabasEntities2())
     {
         ctx.GameLocations.Add(meeting);
         ctx.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
예제 #13
0
        public ActionResult DeleteParticipant(int participantId, int meetingId)
        {
            ICollection <MeetingParticipant> collection;

            using (var ctx = new KlubbdatabasEntities2())
            {
                var participant = ctx.MeetingParticipants.Find(participantId);
                ctx.MeetingParticipants.Remove(participant);
                ctx.SaveChanges();

                collection = ctx.MeetingParticipants.Where(x => x.GameLocationId == meetingId).Include(y => y.Personer).ToList();
            }

            return(PartialView("~/Views/Shared/_Participants.cshtml", collection));
        }
예제 #14
0
        public ActionResult EditMember(Personer person)
        {
            if (!ModelState.IsValid)
            {
                return(View(person));
            }

            using (var ctx = new KlubbdatabasEntities2())
            {
                var model = ctx.Personers.Find(person.ID);
                if (TryUpdateModel(model))
                {
                    ctx.SaveChanges();
                }
            }
            return(RedirectToAction("Index"));
        }
예제 #15
0
        public ActionResult AddParticipants(AddMember model)
        {
            string errors = "";
            ICollection <MeetingParticipant> collection;

            using (var ctx = new KlubbdatabasEntities2())
            {
                GameLocation meeting = ctx.GameLocations.Where(x => x.ID == model.CurrentMeetingId).SingleOrDefault();
                if (meeting == null)
                {
                    meeting = ctx.GameLocations.Add(new GameLocation {
                        ID = model.CurrentMeetingId, Datum = DateTime.Now, Adress = "blä"
                    });
                }
                foreach (var item in model.AvailableMembers.Where(x => x.Add))
                {
                    meeting.MeetingParticipants.Add(new MeetingParticipant {
                        PersonId = item.ID
                    });
                    try
                    {
                        ctx.SaveChanges();
                    }
                    catch (DbEntityValidationException e)
                    {
                        foreach (var eve in e.EntityValidationErrors)
                        {
                            errors += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:\n",
                                                    eve.Entry.Entity.GetType().Name, eve.Entry.State);
                            foreach (var ve in eve.ValidationErrors)
                            {
                                errors += string.Format("- Property: \"{0}\", Value: \"{1}\", Error: \"{2}\"\n",
                                                        ve.PropertyName,
                                                        eve.Entry.CurrentValues.GetValue <object>(ve.PropertyName),
                                                        ve.ErrorMessage);
                            }
                        }
                    }
                }
                collection = ctx.MeetingParticipants.Where(x => x.GameLocationId == model.CurrentMeetingId).Include(y => y.Personer).ToList();
            }
            return(PartialView("~/Views/Shared/_Participants.cshtml", collection));
        }