Esempio n. 1
0
 public void AddCalendar(string username, EPCalendar newCalendar)
 {
     EPCalendar tempCalendar = new EPCalendar();
     using (var db = new EPContext())
     {
         var tempUser = db.Users.FirstOrDefault(u => u.Username == username);
         tempCalendar.Name = newCalendar.Name + "$" + username + "_" + Guid.NewGuid().ToString() + "_C";
         db.Entry(tempUser).Collection(p => p.Calendars).Load();
         var newEntry = new EPEntry(tempUser, tempCalendar, tempUser.Calendars.Count);
         tempUser.Calendars.Add(newEntry);
         tempCalendar.Entryes.Add(newEntry);
         db.SaveChanges();
         db.Entry(tempCalendar).Collection(p => p.Events).Load();
         foreach (var eve in newCalendar.Events)
             tempCalendar.Events.Add(new EPEvent { Calendar = tempCalendar, EventID = eve.EventID, End = eve.End, Start = eve.Start, Summary = eve.Summary });
         db.SaveChanges();
     }
 }
Esempio n. 2
0
 public void AddGroup(string username, string groupName)
 {
     using (var db = new EPContext())
     {
         if (!IsUserInGroup(username, groupName))
         {
             var tempUser = db.Users.FirstOrDefault(u => u.Username == username);
             var tempGroup = db.EPCalendars.FirstOrDefault(g => g.IsGroup && g.Name == groupName);
             db.Entry(tempGroup).Collection(p => p.Entryes).Load();
             db.Entry(tempUser).Collection(p => p.Calendars).Load();
             var newEntry = new EPEntry(tempUser, tempGroup, tempUser.Calendars.Count);
             newEntry.Priority = tempUser.Calendars.Count;
             tempGroup.Entryes.Add(newEntry);
             tempUser.Calendars.Add(newEntry);
             db.SaveChanges();
         }
     }
 }
Esempio n. 3
0
 public void AddEvent(string calendarName, EPEvent newEvent)
 {
     using (var db = new EPContext())
     {
         var calendar = db.EPCalendars.FirstOrDefault(p => p.Name == calendarName);
         db.Entry(calendar).Collection(p => p.Events).Load();
         calendar.Events.Add(newEvent);
         db.SaveChanges();
     }
 }
Esempio n. 4
0
 public void CreateGroup(string username, EPGroup newGroup)
 {
     using (var db = new EPContext())
     {
         var tempUser = db.Users.FirstOrDefault(u => u.Username == username);
         newGroup.Name = newGroup.Name + "$" + username + "_" + Guid.NewGuid().ToString() + "_G";
         db.Entry(tempUser).Collection(p => p.Calendars).Load();
         var newEntry = new EPEntry(tempUser, newGroup, tempUser.Calendars.Count);
         tempUser.Calendars.Add(newEntry);
         newGroup.Entryes.Add(newEntry);
         db.SaveChanges();
     }
 }
Esempio n. 5
0
 public bool IsUserInGroup(string username, string groupName)
 {
     using (var db = new EPContext())
     {
         var tempGroup = db.EPCalendars.FirstOrDefault(g => g.IsGroup && g.Name == groupName);
         db.Entry(tempGroup).Collection(g => g.Entryes).Load();
         foreach(var entry in tempGroup.Entryes)
         {
             db.Entry(entry).Reference(p => p.User).Load();
             if (entry.User.Username == username) return true;
         }
         return false;
     }
 }
Esempio n. 6
0
        public List<EPCalendar> GetUserCalendars(string username)
        {
            using (var db = new EPContext())
            {
                var user = db.Users.FirstOrDefault(p => p.Username == username);
                db.Entry(user).Collection(p => p.Calendars).Load();
                user.Calendars.Sort((p, r) => p.Priority - r.Priority);
                List<EPCalendar> calendars = new List<EPCalendar>();
                foreach(var entry in user.Calendars)
                {

                    db.Entry(entry).Reference(p => p.Calendar).Load();
                    db.Entry(entry.Calendar).Collection(p => p.Events).Load();
                    calendars.Add(entry.Calendar);
                }
                return calendars;
            }
        }
Esempio n. 7
0
        public List<EPCalendar> GetGroupUsersCalendars(string groupName)
        {
            using (var db = new EPContext())
            {
                var group = db.EPCalendars.FirstOrDefault(p => p.IsGroup && p.Name == groupName);
                db.Entry(group).Collection(p => p.Entryes).Load();

                List<EPCalendar> calendars = new List<EPCalendar>();
                foreach (var entry in group.Entryes)
                {
                    db.Entry(entry).Reference(p => p.User).Load();
                    var user = entry.User;
                    db.Entry(user).Collection(p => p.Calendars).Load();

                    calendars.Add(FreeTimeCalendar(user.Calendars, user, entry.Priority));
                }
                return calendars;
            }
        }
Esempio n. 8
0
 public List<EPUser> GetGroupUsers(string groupName)
 {
     using (var db = new EPContext())
     {
         var group = db.EPCalendars.FirstOrDefault(p => p.IsGroup && p.Name == groupName);
         db.Entry(group).Collection(p => p.Entryes).Load();
         List<EPUser> users = new List<EPUser>();
         foreach (var entry in group.Entryes)
         {
             db.Entry(entry).Reference(p => p.User).Load();
             users.Add(entry.User);
         }
         return users;
     }
 }
Esempio n. 9
0
 public EPCalendar GetCalendar(string calendarID)
 {
     using (var db = new EPContext())
     {
         EPCalendar calendar = db.EPCalendars.FirstOrDefault(p => p.Name == calendarID);
         db.Entry(calendar).Collection(p => p.Events).Load();
         return calendar;
     }
 }
Esempio n. 10
0
 public EPCalendar FreeTimeCalendar(List<EPEntry> calendars, EPUser user, int groupIndex)
 {
     calendars.Sort((p, r) => p.Priority - r.Priority);
     EPCalendar tempCal = new EPCalendar();
     tempCal.Entryes.Add(new EPEntry(user,tempCal,0));
     using (var db = new EPContext()) {
         for(int i = 0; i<groupIndex; i++)
         {
             var cal = calendars[i];
             db.Entryes.Attach(cal);
             db.Entry(cal).Reference(p => p.Calendar).Load();
             db.Entry(cal.Calendar).Collection(p => p.Events).Load();
             tempCal.Events.AddRange(cal.Calendar.Events);
         }
     }
     tempCal.Events.ForEach(p => p.Summary = "Bussy");
     return tempCal;
 }