예제 #1
0
        public async Task <IActionResult> CreateEvent(int?ID)
        {
            if (ID == null)
            {
                ChatUserModel admin = await _userManager.GetUserAsync(this.User);

                Models.Events.Event newCalendar = new Models.Events.Event();
                if (admin.AdministratedCalendars == null)
                {
                    admin.AdministratedCalendars = new List <Models.Events.Event>();
                }
                admin.AdministratedCalendars.Add(newCalendar);
                if (admin.Calendars == null)
                {
                    admin.Calendars = new List <ChatUserModel_Event>();
                }
                ChatUserModel_Event JoinTable = new ChatUserModel_Event();
                JoinTable.Calendar      = newCalendar;
                JoinTable.ChatUserModel = admin;
                admin.Calendars.Add(JoinTable);
                newCalendar.Members.Add(JoinTable);
                _context.Events.Add(newCalendar);
                _context.ChatUserModel_Event.Add(JoinTable);
                _context.SaveChanges();
                return(View(newCalendar.Id));
            }
            //Create Calendar here stuff
            return(View(ID));
        }
예제 #2
0
 public async Task AddInvitedUser(string ID, string ChatUser)
 {
     if (Int32.TryParse(ID, out int _ID))
     {
         var Calendar = _context.Events.Where(x => x.Id == _ID).FirstOrDefault();
         if (Calendar != null)
         {
             if (Calendar.Members.Where(x => x.ChatUserModel.ChatUserName == ChatUser).Count() == 0)
             {
                 ChatUserModel user = _context.ChatUserModels.Where(x => x.ChatUserName.ToLower() == ChatUser.ToLower()).FirstOrDefault();
                 if (user != null)
                 {
                     ChatUserModel_Event newrelation = new ChatUserModel_Event();
                     newrelation.Calendar      = Calendar;
                     newrelation.ChatUserModel = user;
                     if (Calendar.Members == null)
                     {
                         Calendar.Members = new List <ChatUserModel_Event>();
                     }
                     Calendar.Members.Add(newrelation);
                     if (user.Calendars == null)
                     {
                         user.Calendars = new List <ChatUserModel_Event>();
                     }
                     user.Calendars.Add(newrelation);
                     _context.ChatUserModel_Event.Add(newrelation);
                     await _context.SaveChangesAsync();
                 }
             }
         }
     }
 }