public MeetingViewModel Create(MeetingViewModel product)
        {
            meetingService.Insert(product);
            Clients.Others.create(product);

            return product;
        }
        public virtual void Insert(MeetingViewModel meeting)
        {
            if (meeting.Attendees == null)
            {
                meeting.Attendees = new int[0];
            }

            if (string.IsNullOrEmpty(meeting.Title))
            {
                meeting.Title = "";
            }

            var entity = meeting.ToEntity();

            foreach (var attendeeId in meeting.Attendees)
            {
                entity.MeetingAttendees.Add(new MeetingAttendee
                {
                    AttendeeID = attendeeId
                });
            }

            db.Meetings.Add(entity);
            db.SaveChanges();

            meeting.MeetingID = entity.MeetingID;
        }
        public virtual void Update(MeetingViewModel meeting)
        {
            if (string.IsNullOrEmpty(meeting.Title))
            {
                meeting.Title = "";
            }

            var entity = db.Meetings.Include("MeetingAttendees").FirstOrDefault(m => m.MeetingID == meeting.MeetingID);

            entity.Title = meeting.Title;
            entity.Start = meeting.Start;
            entity.End = meeting.End;
            entity.Description = meeting.Description;
            entity.IsAllDay = meeting.IsAllDay;
            entity.RoomID = meeting.RoomID;
            entity.RecurrenceID = meeting.RecurrenceID;
            entity.RecurrenceRule = meeting.RecurrenceRule;
            entity.RecurrenceException = meeting.RecurrenceException;
            entity.StartTimezone = meeting.StartTimezone;
            entity.EndTimezone = meeting.EndTimezone;

            foreach (var meetingAttendee in entity.MeetingAttendees.ToList())
            {
                entity.MeetingAttendees.Remove(meetingAttendee);
            }

            if (meeting.Attendees != null)
            {
                foreach (var attendeeId in meeting.Attendees)
                {
                    var meetingAttendee = new MeetingAttendee
                    {
                        MeetingID = entity.MeetingID,
                        AttendeeID = attendeeId
                    };

                    entity.MeetingAttendees.Add(meetingAttendee);
                }
            }

            db.SaveChanges();
        }
 public void Destroy(MeetingViewModel product)
 {
     meetingService.Delete(product);
     Clients.Others.destroy(product);
 }
 public void Update(MeetingViewModel product)
 {
     meetingService.Update(product);
     Clients.Others.update(product);
 }
        public virtual void Delete(MeetingViewModel meeting)
        {
            if (meeting.Attendees == null)
            {
                meeting.Attendees = new int[0];
            }

            var entity = meeting.ToEntity();

            db.Meetings.Attach(entity);

            var attendees = meeting.Attendees.Select(attendee => new MeetingAttendee
            {
                AttendeeID = attendee,
                MeetingID = entity.MeetingID
            });

            foreach (var attendee in attendees)
            {
                db.MeetingAttendees.Attach(attendee);
            }

            entity.MeetingAttendees.Clear();

            var recurrenceExceptions = db.Meetings.Where(m => m.RecurrenceID == entity.MeetingID);

            foreach (var recurrenceException in recurrenceExceptions)
            {
                db.Meetings.Remove(recurrenceException);
            }

            db.Meetings.Remove(entity);
            db.SaveChanges();
        }