Example #1
0
        public void Delete(CALDAVContext mDb, Guid folderId, Guid fileId)
        {
            // eager load the calendar file details
            CalendarFile calendarFile = mDb.CalendarFile
                                        .Include(a => a.FolderNavigation.CalendarFolderInfo)
                                        .Include(a => a.CalendarEvent)
                                        .Include(a => a.CalendarFreeBusy)
                                        .Include(a => a.CalendarJournal)
                                        .Include(a => a.CalendarTimeZone)
                                        .Include(a => a.CalendarToDo)
                                        .Where(a => a.FolderId == folderId && a.CalendarFileId == fileId).SingleOrDefault();


            if (calendarFile == null)
            {
                return;
            }
            // Update Folder CTag
            else
            {
                calendarFile.FolderNavigation.Modified = DateTime.UtcNow;
                // used to trigger CTag RowVersion Update
                calendarFile.FolderNavigation.CalendarFolderInfo.Modified = DateTime.UtcNow;
            }


            foreach (var e in Events)
            {
                e.Calendar = this;
                e.Delete(mDb, calendarFile);
            }
            foreach (var td in ToDos)
            {
                td.Calendar = this;
                td.Delete(mDb, calendarFile);
            }

            /*
             * foreach (var tz in TimeZones)
             * {
             *  tz.Calendar = this;
             *  tz.Delete(mDb, calendarFile);
             * }
             * foreach (var fb in FreeBusy)
             * {
             *  fb.Calendar = this;
             *  fb.Delete(mDb, calendarFile);
             * }
             * foreach (var jn in JournalEntries)
             * {
             *  jn.Calendar = this;
             *  jn.Delete(mDb, calendarFile);
             * }
             */

            if (calendarFile != null)
            {
                mDb.Remove(calendarFile);
            }


            mDb.SaveChanges();
        }
Example #2
0
        public void Save(CALDAVContext mDb, Guid folderId, Guid fileId)
        {
            this.ValidateModel();

            // eager load the calendar file details
            CalendarFile calendarFile = mDb.CalendarFile
                                        .Include(a => a.FolderNavigation.CalendarFolderInfo)
                                        .Include(a => a.CalendarEvent)
                                        .Include(a => a.CalendarFreeBusy)
                                        .Include(a => a.CalendarJournal)
                                        .Include(a => a.CalendarTimeZone)
                                        .Include(a => a.CalendarToDo)
                                        .Where(a => a.FolderId == folderId && a.CalendarFileId == fileId).SingleOrDefault();

            // Create Calendar File
            if (calendarFile == null)
            {
                calendarFile = new CalendarFile
                {
                    FolderId       = folderId,
                    CalendarFileId = fileId,

                    Created = DateTime.UtcNow
                };

                var calendarFolder = mDb.FolderInfo.Include(a => a.CalendarFolderInfo)
                                     .Where(a => a.FolderId == folderId).SingleOrDefault();

                if (calendarFolder == null)
                {
                    throw new Exception($"Calendar folder for folder ID: ({folderId.ToString()}) does not exist in DB context.");
                }

                calendarFolder.Modified = DateTime.UtcNow;
                calendarFolder.CalendarFolderInfo.Modified = DateTime.UtcNow;

                mDb.CalendarFile.Add(calendarFile);
            }
            else
            {
                calendarFile.FolderNavigation.Modified = DateTime.UtcNow;
                // used to trigger CTag RowVersion Update
                calendarFile.FolderNavigation.CalendarFolderInfo.Modified = DateTime.UtcNow;
            }

            // update Calendar File

            calendarFile.Scale    = this.Scale;
            calendarFile.ProdId   = this.ProdID;
            calendarFile.Modified = DateTime.UtcNow;

            foreach (var e in Events)
            {
                e.Calendar = this;
                e.Save(mDb, calendarFile);
            }
            foreach (var td in ToDos)
            {
                td.Calendar = this;
                td.Save(mDb, calendarFile);
            }

            /*
             * foreach (var tz in TimeZones)
             * {
             *  tz.Calendar = this;
             *  tz.Save(mDb, calendarFile);
             * }
             * foreach (var fb in FreeBusy)
             * {
             *  fb.Calendar = this;
             *  fb.Save(mDb, calendarFile);
             * }
             * foreach (var jn in JournalEntries)
             * {
             *  jn.Calendar = this;
             *  jn.Save(mDb, calendarFile);
             * }
             */

            mDb.SaveChanges();
        }