Beispiel #1
0
        public void AddAttendees(int meetingid, int attendeeid)
        {
            var meet            = db.Meetings.Include(x => x.MeetingAttendeesLink).First();
            MeetingAttendees ma = new MeetingAttendees {
                MeetingID = meetingid, AttendeeID = attendeeid
            };

            meet.MeetingAttendeesLink.Add(ma);
            db.SaveChanges();
        }
Beispiel #2
0
        public async Task <object> MeetingSignup(IFormCollection forms)
        {
            var _session = await IsAuthorized();

            if (_session == null)
            {
                return new
                       {
                           Status = "NotLoggedIn"
                       }
            }
            ;

            int meetingid;

            Int32.TryParse(forms["meetingid"], out meetingid);
            var _member = await _context.Member.FirstOrDefaultAsync(m => m.MemberId == _session.MemberId);

            var _meeting = await _context.Meeting.FirstOrDefaultAsync(m => m.MeetingId == meetingid);

            if (_meeting.Type == MeetingType.Meeting && forms["password"] != _meeting.Password)
            {
                return(new
                {
                    Status = "InvalidCredentials"
                });
            }
            var meetingAttendees = new MeetingAttendees
            {
                MemberId  = _member.MemberId,
                MeetingId = meetingid
            };

            var attendee = await _context.MeetingAttendees.FirstOrDefaultAsync(ma => ma.MeetingId == meetingid && ma.MemberId == _session.MemberId);

            if (attendee != null)
            {
                return new
                       {
                           Status  = "Success",
                           Meeting = await GetSingleMeeting(meetingid)
                       }
            }
            ;

            _context.MeetingAttendees.Add(meetingAttendees);
            await _context.SaveChangesAsync();

            return(new
            {
                Status = "Success",
                Meeting = await GetSingleMeeting(meetingid)
            });
        }
        public async Task <IActionResult> Create([Bind("MeetingId,ContactId,EventName,Description,Capacity,Start,End,Password,Color,AllDay,Type,MemberIds")] MeetingViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.GetUserAsync(User);

                var meeting = new Meeting
                {
                    OrganizerId = user.Id,
                    Organizer   = user.FullName,
                    ContactId   = vm.ContactId,
                    EventName   = vm.EventName,
                    Description = vm.Description,
                    Capacity    = vm.Capacity,
                    Start       = vm.Start,
                    End         = vm.End,
                    Password    = vm.Password,
                    Color       = vm.Color,
                    AllDay      = vm.AllDay,
                    Type        = vm.Type
                };
                _context.Add(meeting);
                await _context.SaveChangesAsync();

                if (vm.MemberIds == null)
                {
                    vm.MemberIds = new System.Collections.Generic.List <int>();
                }
                foreach (var memberId in vm.MemberIds)
                {
                    var meetingAttendees = new MeetingAttendees
                    {
                        MeetingId = meeting.MeetingId,
                        MemberId  = memberId
                    };

                    _context.MeetingAttendees.Add(meetingAttendees);
                    await _context.SaveChangesAsync();
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            var members = await _context.Member.OrderBy(c => c.LastName).ToListAsync();

            ViewBag.Members = new MultiSelectList(members, "MemberId", "Email");
            return(View(vm));
        }
        public async Task <IActionResult> Edit(int id, [Bind("MeetingId,ContactId,EventName,Description,Capacity,Start,End,Password,Color,AllDay,Type,MemberIds")] MeetingViewModel vm)
        {
            var meeting = await _context.Meeting
                          .Include(mem => mem.MeetingAttendees)
                          .ThenInclude(ma => ma.Member)
                          .FirstOrDefaultAsync(m => m.MeetingId == id);

            if (id != meeting.MeetingId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    meeting.ContactId   = vm.ContactId;
                    meeting.EventName   = vm.EventName;
                    meeting.Description = vm.Description;
                    meeting.Capacity    = vm.Capacity;
                    meeting.Start       = vm.Start;
                    meeting.End         = vm.End;
                    meeting.Password    = vm.Password;
                    meeting.Color       = vm.Color;
                    meeting.AllDay      = vm.AllDay;
                    meeting.Type        = vm.Type;
                    _context.Update(meeting);
                    await _context.SaveChangesAsync();

                    if (vm.MemberIds == null)
                    {
                        vm.MemberIds = new System.Collections.Generic.List <int>();
                    }
                    var oldMemberIds = meeting.MeetingAttendees.Select(ma => ma.Member.MemberId).ToList();
                    foreach (var memberId in vm.MemberIds)
                    {
                        if (!oldMemberIds.Contains(memberId))
                        {
                            var meetingAttendees = new MeetingAttendees
                            {
                                MeetingId = meeting.MeetingId,
                                MemberId  = memberId
                            };

                            _context.MeetingAttendees.Add(meetingAttendees);
                            await _context.SaveChangesAsync();
                        }
                    }
                    foreach (var oldMemberId in oldMemberIds)
                    {
                        if (!vm.MemberIds.Contains(oldMemberId))
                        {
                            _context.MeetingAttendees.Remove(meeting.MeetingAttendees.FirstOrDefault(ma => ma.MemberId == oldMemberId && ma.MeetingId == meeting.MeetingId));
                            await _context.SaveChangesAsync();
                        }
                    }
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MeetingExists(meeting.MeetingId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            var members = await _context.Member.OrderBy(c => c.LastName).ToListAsync();

            ViewBag.Members = new MultiSelectList(members, "MemberId", "Email");

            return(View(vm));
        }
        public async Task <IActionResult> Create([Bind("FirstName,LastName,Gender,Address,City,ZipCode,Grade,RecruitedBy,Email,Phone,Password,ClubIds,MeetingIds")] MemberViewModel vm)
        {
            if (ModelState.IsValid)
            {
                PasswordHash ph = PasswordHasher.Hash(vm.Password);

                var member = new Member
                {
                    FirstName   = vm.FirstName,
                    LastName    = vm.LastName,
                    Gender      = vm.Gender,
                    Address     = vm.Address,
                    City        = vm.City,
                    ZipCode     = vm.ZipCode,
                    Grade       = vm.Grade,
                    RecruitedBy = vm.RecruitedBy,
                    Email       = vm.Email,
                    Phone       = vm.Phone,
                    Password    = ph.HashedPassword,
                    Salt        = ph.Salt
                };
                _context.Member.Add(member);
                await _context.SaveChangesAsync();

                if (vm.ClubIds == null)
                {
                    vm.ClubIds = new System.Collections.Generic.List <int>();
                }
                if (vm.MeetingIds == null)
                {
                    vm.MeetingIds = new System.Collections.Generic.List <int>();
                }

                // add this new member to the relevant clubs
                foreach (var clubId in vm.ClubIds)
                {
                    var clubMember = new ClubMember
                    {
                        ClubId   = clubId,
                        MemberId = member.MemberId
                    };

                    _context.ClubMember.Add(clubMember);
                    await _context.SaveChangesAsync();
                }
                foreach (var meetingId in vm.MeetingIds)
                {
                    var meetingAttendees = new MeetingAttendees
                    {
                        MeetingId = meetingId,
                        MemberId  = member.MemberId
                    };

                    _context.MeetingAttendees.Add(meetingAttendees);
                    await _context.SaveChangesAsync();
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            var clubs = await _context.Club.OrderBy(c => c.Name).ToListAsync();

            ViewBag.Clubs = new MultiSelectList(clubs, "ClubId", "Name");
            var meetings = await _context.Meeting.OrderBy(m => m.EventName).ToListAsync();

            ViewBag.Meetings = new MultiSelectList(meetings, "MeetingId", "EventName");

            return(View(vm));
        }
        public async Task <IActionResult> Edit(int id, [Bind("MemberId,FirstName,LastName,Gender,Address,City,ZipCode,Grade,Email,Phone,ClubIds,MeetingIds")] MemberViewModel vm)
        {
            var member = await _context.Member
                         .Include(m => m.ClubMembers)
                         .ThenInclude(cm => cm.Club)
                         .Include(m => m.MeetingAttendees)
                         .ThenInclude(ma => ma.Meeting)
                         .FirstOrDefaultAsync(m => m.MemberId == id);

            if (id != member.MemberId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    member.FirstName = vm.FirstName;
                    member.LastName  = vm.LastName;
                    member.Gender    = vm.Gender;
                    member.Address   = vm.Address;
                    member.City      = vm.City;
                    member.ZipCode   = vm.ZipCode;
                    member.Grade     = vm.Grade;
                    member.Email     = vm.Email;
                    member.Phone     = vm.Phone;

                    _context.Update(member);
                    await _context.SaveChangesAsync();

                    if (vm.ClubIds == null)
                    {
                        vm.ClubIds = new System.Collections.Generic.List <int>();
                    }

                    var oldClubIds = member.ClubMembers.Select(cm => cm.Club.ClubId).ToList();
                    foreach (var clubId in vm.ClubIds)
                    {
                        if (!oldClubIds.Contains(clubId))
                        {
                            var clubMember = new ClubMember
                            {
                                ClubId   = clubId,
                                MemberId = member.MemberId
                            };

                            _context.ClubMember.Add(clubMember);
                            await _context.SaveChangesAsync();
                        }
                    }
                    foreach (var oldClubId in oldClubIds)
                    {
                        if (!vm.ClubIds.Contains(oldClubId))
                        {
                            _context.ClubMember.Remove(member.ClubMembers.FirstOrDefault(cm => cm.ClubId == oldClubId && cm.MemberId == member.MemberId));
                            await _context.SaveChangesAsync();
                        }
                    }

                    if (vm.MeetingIds == null)
                    {
                        vm.MeetingIds = new System.Collections.Generic.List <int>();
                    }

                    var oldMeetingIds = member.MeetingAttendees.Select(ma => ma.Meeting.MeetingId).ToList();
                    foreach (var meetingId in vm.MeetingIds)
                    {
                        if (!oldMeetingIds.Contains(meetingId))
                        {
                            var meetingAttendees = new MeetingAttendees
                            {
                                MeetingId = meetingId,
                                MemberId  = member.MemberId
                            };

                            _context.MeetingAttendees.Add(meetingAttendees);
                            await _context.SaveChangesAsync();
                        }
                    }
                    foreach (var oldMeetingId in oldMeetingIds)
                    {
                        if (!vm.MeetingIds.Contains(oldMeetingId))
                        {
                            _context.MeetingAttendees.Remove(member.MeetingAttendees.FirstOrDefault(ma => ma.MeetingId == oldMeetingId && ma.MemberId == member.MemberId));
                            await _context.SaveChangesAsync();
                        }
                    }

                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MemberExists(member.MemberId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            var clubs = await _context.Club.OrderBy(c => c.Name).ToListAsync();

            ViewBag.Clubs = new MultiSelectList(clubs, "ClubId", "Name");
            var meetings = await _context.Meeting.OrderBy(m => m.EventName).ToListAsync();

            ViewBag.Meetings = new MultiSelectList(meetings, "MeetingId", "EventName");

            return(View(vm));
        }
        /// <summary>
        /// Runs job
        /// </summary>
        /// <param name="state">state information</param>
        private async void RunJob(object state)
        {
            try
            {
                string token = await AuthenticationHelper.GetAccessTokenAsync(_configuration, _httpClientFactory);

                GraphServiceClient graphserviceClient = new GraphServiceClient(
                    new DelegateAuthenticationProvider(
                        (requestMessage) =>
                {
                    requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", token);

                    return(Task.FromResult(0));
                }));
                var callsInformation = await DocumentDBRepository.GetItemsAsync <CallInfo>(c => c.Status == null);

                foreach (var call in callsInformation)
                {
                    try
                    {
                        var participants = await graphserviceClient.Communications.Calls[call.CallId.ToString()].Participants
                                           .Request()
                                           .GetAsync();
                        var attendees = new List <Models.Attendee>();
                        foreach (var participant in participants.CurrentPage)
                        {
                            if (participant.Info.Identity.User != null)
                            {
                                var attendee = new Models.Attendee()
                                {
                                    DisplayName = participant.Info.Identity.User.DisplayName,
                                    AadId       = participant.Info.Identity.User.Id,
                                };
                                attendees.Add(attendee);
                            }
                        }

                        var meetingAttendees = new MeetingAttendees()
                        {
                            LogTime         = DateTime.UtcNow.ToString(),
                            CallId          = call.CallId,
                            EventId         = call.EventId,
                            ListOfAttendees = attendees
                        };
                        if (meetingAttendees.ListOfAttendees.Count > 0)
                        {
                            await DocumentDBRepository.CreateItemAsync <MeetingAttendees>(meetingAttendees);
                        }
                    }
                    catch (Exception e)
                    {
                        _logger.LogError(e.Message + ' ' + e.StackTrace);

                        if (((ServiceException)e).StatusCode == System.Net.HttpStatusCode.NotFound)
                        {
                            call.Status = (int?)System.Net.HttpStatusCode.NotFound;
                            await DocumentDBRepository.UpdateItemAsync(call.Id, call);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message + ' ' + e.StackTrace);
            }
        }
 public ActionResult AddAttendee([FromBody] MeetingAttendees ma)
 {
     rep.AddAttendees(ma.MeetingID, ma.AttendeeID);
     return(Ok());
 }