Ejemplo n.º 1
0
        private static void AddRandomGuestList(EventManagerDBContext db, Meeting newEvent)
        {
            Random rand = new Random();

            // Get all contacts
            var contactList = new List <Contact>();

            contactList.AddRange(from c in db.Contacts select c);

            // Randomly select contacts for test event
            int noOfGuests = rand.Next(0, contactList.Count / 2);

            for (int i = 0; i < noOfGuests; i++)
            {
                int guestNo = rand.Next(0, contactList.Count - 1);
                var contact = contactList[guestNo];

                var guest =
                    new MeetingGuest
                {
                    Contact     = contact,
                    GuestStatus = GustArrivalStatus.Unknown,
                    Meeting     = newEvent,
                };

                db.EventGuests.Add(guest);
                contactList.RemoveAt(guestNo);
            }

            db.SaveChanges();
        }
Ejemplo n.º 2
0
        public static EventGuest AddGuestToEvent(int eventId, ContactItemModel newGuest)
        {
            if (eventId < 0)
            {
                throw new ArgumentException($"{nameof(eventId)}: {eventId}");
            }
            else
            {
                using (var db = new EventManagerDBContext())
                {
                    // Look for event guest if it exists
                    var eventQuery = from eventGuest in db.EventGuests
                                     where eventGuest.ContactID == newGuest.ID &&
                                     eventGuest.MeetingID == eventId
                                     select eventGuest;
                    var result = eventQuery.FirstOrDefault();
                    if (result == null)
                    {
                        var meetingGuest = new MeetingGuest
                        {
                            ContactID   = newGuest.ID,
                            MeetingID   = eventId,
                            GuestStatus = GustArrivalStatus.Unknown
                        };

                        db.EventGuests.Add(meetingGuest);
                        db.SaveChanges();
                        var guest = new EventGuest
                        {
                            ContactID   = newGuest.ID,
                            Guest       = newGuest,
                            GuestStatus = GustArrivalStatus.Unknown,
                            ID          = meetingGuest.MeetingGuestID
                        };

                        return(guest);
                    }
                    else
                    {
                        return(new EventGuest
                        {
                            ContactID = result.ContactID,
                            Guest = newGuest,
                            ID = result.ContactID,
                            GuestStatus = result.GuestStatus
                        });
                    }
                }
            }
        }