Beispiel #1
0
        /// <summary>
        /// Sets the appointment category to give the appointment the correct color
        /// </summary>
        /// <param name="item">The item to set</param>
        /// <param name="state">The appointment state to set to the appointment</param>
        public static void SetAppointmentState(this AppointmentItem item, AppointmentState state)
        {
            var newCategories = new List <string>();

            // get the previous categories and remove our categories
            if (!string.IsNullOrEmpty(item.Categories))
            {
                foreach (var itm in item.Categories.Split(';'))
                {
                    // Preserve other categories.
                    if (!AppointmentState.IsValidAppointmentStateName(itm))
                    {
                        newCategories.Add(itm);
                    }
                }
            }

            // set our new categories
            newCategories.Insert(0, state.Name);

            if (state == AppointmentState.Modified)
            {
                item.SetAppointmentModificationDate(DateTime.Now);
            }

            item.Categories = string.Join(";", newCategories);

            // Update the previous sate of the appointment, if the current state is not syncerror.
            var previousState = item.GetAppointmentCustomId(Constants.FieldAppointmentState);

            if (previousState.HasValue && previousState.Value != AppointmentState.SyncError.Value)
            {
                item.SetAppointmentCustomId(Constants.FieldAppointmentPreviousState, previousState);
            }

            item.SetAppointmentCustomId(Constants.FieldAppointmentState, state.Value);
        }