Beispiel #1
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"));
 }
Beispiel #2
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"));
 }
Beispiel #3
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"));
 }
Beispiel #4
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"));
        }
Beispiel #5
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"));
 }
Beispiel #6
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));
        }
Beispiel #7
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"));
        }
Beispiel #8
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));
        }