示例#1
0
        public async Task ConnectUsers(int meetingId)
        {
            List <User> FreeUsers = await _context.User.Where(u => u.MeetingID == meetingId && u.MeetingOrganizer == false)
                                    .OrderBy(u => rng.Next())
                                    .ToListAsync();

            if (FreeUsers.Count % 2 != 0)
            {
                FreeUsers.RemoveAt(FreeUsers.Count - 1); // mičemo zadnjeg da ih bude paran broj
            }

            for (int i = 0; i < FreeUsers.Count(); i += 2)
            {
                // generiramo AgreedMeeting i upisujemo njegov ID u 2 korisnika i šaljemo im mail
                AgreedMeeting AgreedMeeting = new AgreedMeeting
                {
                    MeetingID = meetingId
                };

                _context.AgreedMeeting.Add(AgreedMeeting);
                _context.SaveChanges();

                AgreedMeeting NewAgreedMeeting = _context.AgreedMeeting.Where(am => am.MeetingID == meetingId).LastOrDefault();

                User FirstUser = (from x in _context.User
                                  where x.Id == FreeUsers[i].Id
                                  select x).First();
                User SecondUser = (from x in _context.User
                                   where x.Id == FreeUsers[i + 1].Id && x.DepartmentID != FirstUser.DepartmentID && x.MeetingID == FirstUser.MeetingID
                                   select x).First();

                FirstUser.AgreedMeetingID  = NewAgreedMeeting.AgreedMeetingID;
                SecondUser.AgreedMeetingID = NewAgreedMeeting.AgreedMeetingID;

                _context.SaveChanges();
            }

            MailSender MailSender = new MailSender();

            foreach (User u in FreeUsers)
            {
                string SecondUsername = (from x in _context.User
                                         where x.AgreedMeetingID == u.AgreedMeetingID && x.Id != u.Id
                                         select x).First().UserName;

                await MailSender.Send(u.Email,
                                      $"You have been connected with a buddy",
                                      $"Dear {u.UserName}, <br/>your buddy is {SecondUsername}! You can log in <a href='https://localhost:44315/login'>here</a> to agree on a meeting place and time.");
            }
        }
示例#2
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            AgreedMeeting = await _context.AgreedMeeting
                            .Include(a => a.Meeting).FirstOrDefaultAsync(m => m.AgreedMeetingID == id);

            if (AgreedMeeting == null)
            {
                return(NotFound());
            }
            return(Page());
        }
示例#3
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            AgreedMeeting = await _context.AgreedMeeting
                            .Include(a => a.Meeting).FirstOrDefaultAsync(m => m.AgreedMeetingID == id);

            if (AgreedMeeting == null)
            {
                return(NotFound());
            }
            ViewData["MeetingID"] = new SelectList(_context.Meeting, "MeetingID", "MeetingID");
            return(Page());
        }
示例#4
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            AgreedMeeting = await _context.AgreedMeeting.FindAsync(id);

            if (AgreedMeeting != null)
            {
                _context.AgreedMeeting.Remove(AgreedMeeting);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
示例#5
0
        public async Task <IActionResult> OnPost(string meetingLink)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            //Item.UserId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            Item.Name = this.User.FindFirstValue(ClaimTypes.Name);

            AgreedMeeting SourceMeeting = await _context.AgreedMeeting.Where(am => am.Link == meetingLink).FirstOrDefaultAsync();

            Item.AgreedMeetingID = SourceMeeting.AgreedMeetingID;
            //Item.UserID = 1;
            //Item.UserId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);

            _context.ChatMessage.Add(Item);
            await _context.SaveChangesAsync();

            return(RedirectToPage("Chat", new { meetingLink }));
        }