private RecurringEventNameValue(string name, RecurringEvent recurringEvent) { Name = name; Value = recurringEvent; }
private void ImportEventsToNewCalendar(IICalendarCollection collection) { var cctrl = new CalendarApiController(); var ectrl = new EventApiController(); var rectrl = new REventApiController(); //loop through calendar in collection foreach (var cal in collection) { //Create the new calendar string name = "New Imported Calendar"; if (cal.Properties["X-WR-CALNAME"] != null) { if (!String.IsNullOrEmpty(cal.Properties["X-WR-CALNAME"].Value.ToString())) { name = cal.Properties["X-WR-CALNAME"].Value.ToString(); } } var calendar = cctrl.PostSave(new ECalendar() { Id = 0, Calendarname = name, DisplayOnSite = false, IsGCal = false, GCalFeedUrl = "", ViewMode = "month", Color = "#000000", TextColor = "#FFFFFF" }); //loop through events in calendar foreach (var e in cal.Events) { //check if it is an reccuring event if (e.RecurrenceRules.Count > 0) { var revent = new RecurringEvent() { allDay = e.IsAllDay, title = e.Summary, start = e.Start.Date, end = e.Start.Date, calendarId = calendar.Id, categories = String.Join(",", e.Categories), Id = 0 }; revent.monthly_interval = (int)MonthlyIntervalEnum.First; RecurrencePattern rp = (RecurrencePattern)e.RecurrenceRules[0]; switch (rp.Frequency) { case FrequencyType.Daily: { revent.frequency = (int)FrequencyTypeEnum.Daily; break; } case FrequencyType.Monthly: { revent.frequency = (int)FrequencyTypeEnum.Monthly; break; } case FrequencyType.Weekly: { revent.frequency = (int)FrequencyTypeEnum.Weekly; break; } default: { revent.frequency = (int)FrequencyTypeEnum.Monthly; break; } } switch (rp.ByDay[0].DayOfWeek) { case DayOfWeek.Monday: { revent.day = (int)DayOfWeekEnum.Mon; break; } case DayOfWeek.Tuesday: { revent.day = (int)DayOfWeekEnum.Tue; break; } case DayOfWeek.Wednesday: { revent.day = (int)DayOfWeekEnum.Wed; break; } case DayOfWeek.Thursday: { revent.day = (int)DayOfWeekEnum.Thu; break; } case DayOfWeek.Friday: { revent.day = (int)DayOfWeekEnum.Fri; break; } case DayOfWeek.Saturday: { revent.day = (int)DayOfWeekEnum.Sat; break; } case DayOfWeek.Sunday: { revent.day = (int)DayOfWeekEnum.Sun; break; } } rectrl.PostSave(revent); } else { ectrl.PostSave(new EventCalendar.Core.Models.Event() { allDay = e.IsAllDay, calendarId = calendar.Id, title = e.Summary, start = e.Start.Date, end = e.End.Date, Id = 0, categories = String.Join(",", e.Categories) }); } } } }
private void ImportEventsIntoExistingCalendar(IICalendarCollection collection, int calendar_id) { var cctrl = new CalendarApiController(); var ectrl = new EventApiController(); var rectrl = new REventApiController(); //loop through calendar in collection foreach (var cal in collection) { //loop through events in calendar foreach (var e in cal.Events) { //check if it is an reccuring event if (e.RecurrenceRules.Count > 0) { var revent = new RecurringEvent() { allDay = e.IsAllDay, title = e.Summary, start = e.Start.Date, end = e.Start.Date, calendarId = calendar_id, categories = String.Join(",", e.Categories), Id = 0 }; revent.monthly_interval = (int)MonthlyIntervalEnum.First; RecurrencePattern rp = (RecurrencePattern)e.RecurrenceRules[0]; switch (rp.Frequency) { case FrequencyType.Daily: { revent.frequency = (int)FrequencyTypeEnum.Daily; break; } case FrequencyType.Monthly: { revent.frequency = (int)FrequencyTypeEnum.Monthly; break; } case FrequencyType.Weekly: { revent.frequency = (int)FrequencyTypeEnum.Weekly; break; } default: { revent.frequency = (int)FrequencyTypeEnum.Monthly; break; } } switch (e.Start.DayOfWeek) { case DayOfWeek.Monday: { revent.day = (int)DayOfWeekEnum.Mon; break; } case DayOfWeek.Tuesday: { revent.day = (int)DayOfWeekEnum.Tue; break; } case DayOfWeek.Wednesday: { revent.day = (int)DayOfWeekEnum.Wed; break; } case DayOfWeek.Thursday: { revent.day = (int)DayOfWeekEnum.Thu; break; } case DayOfWeek.Friday: { revent.day = (int)DayOfWeekEnum.Fri; break; } case DayOfWeek.Saturday: { revent.day = (int)DayOfWeekEnum.Sat; break; } case DayOfWeek.Sunday: { revent.day = (int)DayOfWeekEnum.Sun; break; } } rectrl.PostSave(revent); } else { ectrl.PostSave(new EventCalendar.Core.Models.Event() { allDay = e.IsAllDay, calendarId = calendar_id, title = e.Summary, start = e.Start.Date, end = e.End.Date, Id = 0, categories = String.Join(",", e.Categories) }); } } } }
public MessageStatus AddEvent(RecurringEvent newEvent) { Query = "INSERT INTO RecurringEvents([Name], [Location], [Type], [Note], [EventDate], [ContactId], [Status], [EventEndDate], [UserId]) VALUES(@Name, @Location, @Type, @Note, @EventDate, @ContactId, @Status, @EventEndDate, @UserId);"; try { SqlConnection.Open(); SqlCommand sqlCommand = new SqlCommand(Query, SqlConnection); sqlCommand.Parameters.Add("@Name", SqlDbType.VarChar).Value = newEvent.Name; sqlCommand.Parameters.Add("@Location", SqlDbType.VarChar).Value = newEvent.Location; sqlCommand.Parameters.Add("@Type", SqlDbType.VarChar).Value = newEvent.Type; sqlCommand.Parameters.Add("@Note", SqlDbType.VarChar).Value = newEvent.Note; sqlCommand.Parameters.Add("@Status", SqlDbType.VarChar).Value = newEvent.Status; sqlCommand.Parameters.AddWithValue("@EventDate", SqlDbType.DateTime).Value = newEvent.EventDate; sqlCommand.Parameters.Add("@UserId", SqlDbType.Int).Value = newEvent.UserId; SqlParameter contactId = new SqlParameter("ContactId", SqlDbType.Int); if (newEvent.ContactId == 0) { contactId.Value = DBNull.Value; } else { contactId.Value = newEvent.ContactId; } sqlCommand.Parameters.Add(contactId); SqlParameter eventEndDate = new SqlParameter("@EventEndDate", SqlDbType.DateTime); if (newEvent.EventEndDate == DateTime.MinValue) { eventEndDate.Value = DBNull.Value; } else { eventEndDate.Value = newEvent.EventEndDate; } sqlCommand.Parameters.Add(eventEndDate); var i = sqlCommand.ExecuteNonQuery(); if (i > 0) { MessageStatus.Message = "Event Added Successfully!!"; MessageStatus.ErrorStatus = false; } else { throw new Exception("Error, Data Not Added!"); } } catch (Exception ex) { _logger.Error(ex); MessageStatus.Message = ex.Message; MessageStatus.ErrorStatus = true; } finally { SqlConnection.Close(); } return(MessageStatus); }
public ActionResult DeleteRecurringEvent(RecurringEvent e) { this._db.Delete <RecurringEvent>(e.Id); return(RedirectToAction("ShowRecurringEvents", new { id = e.calendarId })); }
public List <RecurringEvent> GetEvents(int userId) { List <RecurringEvent> recurringEventList = new List <RecurringEvent>(); Query = "SELECT RecurringEvents.*, Contacts.ContactName FROM RecurringEvents LEFT JOIN Contacts ON RecurringEvents.ContactId = Contacts.ContactId WHERE RecurringEvents.UserId = @UserId ORDER BY RecurringEvents.EventDate DESC"; try { SqlConnection.Open(); SqlCommand sqlCommand = new SqlCommand(Query, SqlConnection); sqlCommand.Parameters.Add("@UserId", SqlDbType.Int).Value = userId; SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(); while (sqlDataReader.Read()) { RecurringEvent recurringEvent = new RecurringEvent { Id = (int)sqlDataReader["Id"], Name = sqlDataReader["Name"].ToString(), Location = sqlDataReader["Location"].ToString(), Type = sqlDataReader["Type"].ToString(), Note = sqlDataReader["Note"].ToString(), EventDate = (DateTime)sqlDataReader["EventDate"], Status = sqlDataReader["Status"].ToString(), UserId = (int)sqlDataReader["UserId"] }; if (sqlDataReader["ContactId"] == DBNull.Value) { recurringEvent.ContactId = 0; } else { recurringEvent.ContactId = (int)sqlDataReader["ContactId"]; } if (sqlDataReader["ContactName"] == DBNull.Value) { recurringEvent.ContactName = ""; } else { recurringEvent.ContactName = sqlDataReader["ContactName"].ToString(); } if (sqlDataReader["EventEndDate"] == DBNull.Value) { recurringEvent.EventEndDate = DateTime.MinValue; } else { recurringEvent.EventEndDate = (DateTime)sqlDataReader["EventEndDate"]; } recurringEventList.Add(recurringEvent); } } catch (Exception ex) { _logger.Error(ex); } finally { SqlConnection.Close(); } return(recurringEventList); }
//Update Contact public MessageStatus UpdateEvent(RecurringEvent updatingEvent) { Query = "UPDATE RecurringEvents SET [Name] = @Name, [Location] = @Location, [Type] = @Type, [Note] = @Note, [EventDate] = @EventDate, [ContactId] = @ContactId, [Status] = @Status, [EventEndDate] = @EventEndDate WHERE [Id] = @Id AND [UserId] = @UserId;"; try { SqlConnection.Open(); SqlCommand sqlCommand = new SqlCommand(Query, SqlConnection); sqlCommand.Parameters.Add("@Id", SqlDbType.Int).Value = updatingEvent.Id; sqlCommand.Parameters.Add("@UserId", SqlDbType.Int).Value = UserSession.UserData.Id; sqlCommand.Parameters.Add("@Name", SqlDbType.VarChar).Value = updatingEvent.Name; sqlCommand.Parameters.Add("@Location", SqlDbType.VarChar).Value = updatingEvent.Location; sqlCommand.Parameters.Add("@Type", SqlDbType.VarChar).Value = updatingEvent.Type; sqlCommand.Parameters.Add("@Note", SqlDbType.VarChar).Value = updatingEvent.Note; sqlCommand.Parameters.Add("@Status", SqlDbType.VarChar).Value = updatingEvent.Status; sqlCommand.Parameters.AddWithValue("@EventDate", SqlDbType.DateTime).Value = updatingEvent.EventDate; SqlParameter contactId = new SqlParameter("ContactId", SqlDbType.Int); if (updatingEvent.ContactId == 0) { contactId.Value = DBNull.Value; } else { contactId.Value = updatingEvent.ContactId; } sqlCommand.Parameters.Add(contactId); SqlParameter eventEndDate = new SqlParameter("@EventEndDate", SqlDbType.DateTime); if (updatingEvent.EventEndDate == DateTime.MinValue) { eventEndDate.Value = DBNull.Value; } else { eventEndDate.Value = updatingEvent.EventEndDate; } sqlCommand.Parameters.Add(eventEndDate); var i = sqlCommand.ExecuteNonQuery(); if (i > 0) { MessageStatus.Message = "Event Updated Successfully!!"; MessageStatus.ErrorStatus = false; } else { throw new Exception("Error, Data Not Updated!"); } } catch (Exception ex) { _logger.Error(ex); MessageStatus.Message = ex.Message; MessageStatus.ErrorStatus = true; } finally { SqlConnection.Close(); } return(MessageStatus); }
private RecurringEvent(RecurringEvent parent) { Parent = parent; }
public ActionResult GetEventDetails(int id, int calendar, int type = 0) { EventLocation l = null; EventDetailsModel evm = null; if (type == 0) { //Fetch Event CalendarEntry e = this._db.Single <CalendarEntry>("SELECT * FROM ec_events WHERE id=@0 AND calendarid = @1", id, calendar); //If it has a location fetch it if (e.locationId != 0) { l = this._db.Single <EventLocation>("SELECT * FROM ec_locations WHERE id = @0", e.locationId); } //Fetch all Descriptions Dictionary <string, EventDesciption> descriptions = this._db.Query <EventDesciption>("SELECT * FROM ec_eventdescriptions WHERE eventid = @0 AND type = 0 AND calendarid = @1", id, calendar).ToDictionary(x => x.CultureCode); evm = new EventDetailsModel() { Title = e.title, LocationId = e.locationId, Location = l, Descriptions = descriptions }; if (null != e.start) { evm.StartDate = ((DateTime)e.start).ToString("F", CultureInfo.CurrentCulture); } if (null != e.end) { evm.EndDate = ((DateTime)e.end).ToString("F", CultureInfo.CurrentCulture); } } else if (type == 1) { RecurringEvent e = ApplicationContext.DatabaseContext.Database.Single <RecurringEvent>("SELECT * FROM ec_recevents WHERE id=@0 AND calendarid = @1", id, calendar); if (e.locationId != 0) { l = ApplicationContext.DatabaseContext.Database.Single <EventLocation>("SELECT * FROM ec_locations WHERE id = @0", e.locationId); } Schedule schedule = new Schedule(new Event() { Title = e.title, DaysOfWeekOptions = (DayOfWeekEnum)e.day, FrequencyTypeOptions = (FrequencyTypeEnum)e.frequency, MonthlyIntervalOptions = (MonthlyIntervalEnum)e.monthly_interval }); //Fetch all Descriptions Dictionary <string, EventDesciption> descriptions = this._db.Query <EventDesciption>("SELECT * FROM ec_eventdescriptions WHERE eventid = @0 AND type = 1 AND calendarid = @1", id, calendar).ToDictionary(x => x.CultureCode); evm = new EventDetailsModel() { Title = e.title, LocationId = e.locationId, Location = l, StartDate = ((DateTime)schedule.NextOccurrence(DateTime.Now)).ToString("F", CultureInfo.CurrentCulture), Descriptions = descriptions }; } return(PartialView("EventDetails", evm)); }
private async void UpdateRecurringEvent() { if (tbx_name.Text.Equals("")) { MessageBox.Show(Strings.ErrorEmptyName); return; } RecurringEventRepository eventRepository = RecurringEventRepository.Instance; temporaryRecurringEvent.Name = tbx_name.Text; temporaryRecurringEvent.TypeName = cbx_type.Text; temporaryRecurringEvent.Location = tbx_location.Text; temporaryRecurringEvent.CreatedDate = dtp_date.Value; temporaryRecurringEvent.Note = rtbx_note.Text; RecurringEvent recurringEvent = new RecurringEvent(); recurringEvent.Status = cbx_frequency.Text; recurringEvent.EndDate = dtp_enddate.Value; if (temporaryRecurringEvent.TypeName.Equals("Task")) { temporaryRecurringEvent.Type = false; } else { temporaryRecurringEvent.Type = true; } Contact contact = (Contact)cbx_contact.SelectedItem; if (contact == null) { if (string.IsNullOrWhiteSpace(cbx_contact.Text)) { temporaryRecurringEvent.ContactID = 0; } else { ContactRepository contactRepository = ContactRepository.Instance; temporaryRecurringEvent.ContactID = await Task.Run(() => contactRepository.AddContact(new Contact { Name = cbx_contact.Text, UserID = Instances.User.ID })); } } else { temporaryRecurringEvent.ContactID = contact.ID; } if (chbx_infinite.Checked) { temporaryRecurringEvent.EndDate = DateTime.MinValue; } else { temporaryRecurringEvent.EndDate = dtp_enddate.Value; } temporaryRecurringEvent.Status = cbx_frequency.Text; bool result = false; result = await Task.Run(() => eventRepository.EditRecurringEvent(temporaryRecurringEvent)); if (temporaryRecurringEvent.ID > 0 && result) { MessageBox.Show(Strings.EditRecurringEventOkay, Strings.Success); Dispose(); } else { MessageBox.Show(Strings.SomethingError, Strings.Error); } }