Exemplo n.º 1
0
 private void AddNoteToDate(DateTime dateTime, string note)
 {
     using var _nat02Context = new NAT02Context();
     try
     {
         // Exists
         if (_nat02Context.EoiCalendar.Any(c => c.Year == dateTime.Year && c.Month == dateTime.Month && c.Day == dateTime.Day))
         {
             EoiCalendar eoiCalendar = _nat02Context.EoiCalendar.First(c => c.Year == dateTime.Year && c.Month == dateTime.Month && c.Day == dateTime.Day);
             eoiCalendar.Notes     += System.Environment.NewLine + note;
             eoiCalendar.DomainName = user.DomainName;
             _nat02Context.SaveChanges();
         }
         else
         {
             EoiCalendar eoiCalendar = new EoiCalendar
             {
                 Year       = (Int16)dateTime.Year,
                 Month      = (byte)dateTime.Month,
                 Day        = (byte)dateTime.Day,
                 DomainName = user.DomainName,
                 Notes      = note
             };
             _nat02Context.EoiCalendar.Add(eoiCalendar);
             _nat02Context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("There was an error processing your request. It may have been parially processed" + System.Environment.NewLine + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         IMethods.WriteToErrorLog("RecurringEventWindow => AddNoteToDate => Date: " + dateTime.ToLongDateString() + " => Note: " + note, ex.Message, user);
     }
     _nat02Context.Dispose();
 }
        private void Calendar_DayChanged(object sender, Jarloo.Calendar.DayChangedEventArgs e)
        {
            DateTime d = e.Day.Date;

            using var _nat02Context = new NAT02Context();
            // Delete from table
            if (string.IsNullOrEmpty(e.Day.Notes) || string.IsNullOrWhiteSpace(e.Day.Notes))
            {
                // Exists
                if (_nat02Context.EoiCalendar.Any(c => c.Year == (short)d.Year && c.Month == (byte)d.Month && c.Day == (byte)d.Day))
                {
                    if (_nat02Context.EoiCalendar.First(c => c.Year == (short)d.Year && c.Month == (byte)d.Month && c.Day == (byte)d.Day).ActionDateTime < timeEnteredCalendar || _nat02Context.EoiCalendar.First(c => c.Year == (short)d.Year && c.Month == (byte)d.Month && c.Day == (byte)d.Day).DomainName == user.DomainName)
                    {
                        // Remove
                        EoiCalendar eoiCalendar = _nat02Context.EoiCalendar.First(c => c.Year == (short)d.Year && c.Month == (byte)d.Month && c.Day == (byte)d.Day);
                        _nat02Context.EoiCalendar.Remove(eoiCalendar);
                        _nat02Context.SaveChanges();
                        _nat02Context.Dispose();
                    }
                    else
                    {
                        MessageBox.Show("There appears to have been a change made by '" + _nat02Context.EoiCalendar.First(c => c.Year == (short)d.Year && c.Month == (byte)d.Month && c.Day == (byte)d.Day).DomainName + "' to this date before you deleted the note. Please re-open the calendar to load the information.", "Prevoiusly changed", MessageBoxButton.OK, MessageBoxImage.Information);
                        _nat02Context.Dispose();
                    }
                }
            }
            // Insert or Update
            else
            {
                // Exists
                if (_nat02Context.EoiCalendar.Any(c => c.Year == (short)d.Year && c.Month == (byte)d.Month && c.Day == (byte)d.Day))
                {
                    if (_nat02Context.EoiCalendar.First(c => c.Year == (short)d.Year && c.Month == (byte)d.Month && c.Day == (byte)d.Day).ActionDateTime < timeEnteredCalendar || _nat02Context.EoiCalendar.First(c => c.Year == (short)d.Year && c.Month == (byte)d.Month && c.Day == (byte)d.Day).DomainName == user.DomainName)
                    {
                        EoiCalendar eoiCalendar = _nat02Context.EoiCalendar.First(c => c.Year == (short)d.Year && c.Month == (byte)d.Month && c.Day == (byte)d.Day);
                        eoiCalendar.Notes      = e.Day.Notes;
                        eoiCalendar.DomainName = user.DomainName;
                        _nat02Context.SaveChanges();
                        _nat02Context.Dispose();
                    }
                    else
                    {
                        MessageBox.Show("There appears to have been a change made by '" + _nat02Context.EoiCalendar.First(c => c.Year == (short)d.Year && c.Month == (byte)d.Month && c.Day == (byte)d.Day).DomainName + "' to this date before you altered the note. Please re-open the calendar to load the information.", "Prevoiusly changed", MessageBoxButton.OK, MessageBoxImage.Information);
                        _nat02Context.Dispose();
                    }
                }
                // New
                else
                {
                    EoiCalendar eoiCalendar = new EoiCalendar
                    {
                        Day        = (byte)d.Day,
                        Month      = (byte)d.Month,
                        Year       = (Int16)d.Year,
                        DomainName = user.DomainName,
                        Notes      = e.Day.Notes
                    };
                    _nat02Context.EoiCalendar.Add(eoiCalendar);
                    _nat02Context.SaveChanges();
                    _nat02Context.Dispose();
                }
            }
        }