public void GenerateIcalForCalendarEvent_GivenValidEventId_ReturnsModelWithIcalData() { // Arrange var eventId = Guid.NewGuid(); var eventData = new CalEventDm() { CalendarEntryId = eventId, UserId = "MrTestId", Title = "Event 1", Description = "This is a test event.", DateFrom = new DateTime(2022, 1, 1, 12, 15, 0), DateTo = new DateTime(2022, 1, 1, 12, 30, 0), AllDay = false }; _scheduleRepo.Setup(x => x.GetCalendarEvent(eventId)).Returns(eventData); var expectedContentType = "text/calendar"; // Act var result = _schedulerPresentationService.GenerateIcalForCalendarEvent(eventId); // Assert result.ContentType.ShouldBe(expectedContentType); result.Data.ShouldNotBeNull(); result.FileName.Contains(".ics").ShouldBeTrue(); }
public Guid CreateCalendarEvent(CalEventDm entry) { var mappedEntry = ConvertCalendarEventDomainModelToEntity(entry); _context.CalendarEvents.Attach(mappedEntry); _context.Entry(mappedEntry).State = EntityState.Added; _context.SaveChanges(); return(mappedEntry.CalendarEventId); }
/// <summary> /// Convert a <see cref="CalEventDm"/> to a <see cref="CalendarEvent"/>. /// </summary> /// <param name="entry">The domain model to convert.</param> /// <returns>The converted <see cref="CalendarEvent"/>.</returns> private CalendarEvent ConvertCalendarEventDomainModelToEntity(CalEventDm entry) { var newEntity = new CalendarEvent(); newEntity.AllDay = entry.AllDay; newEntity.CalendarEventId = entry.CalendarEntryId; newEntity.DateFrom = entry.DateFrom; newEntity.DateTo = entry.DateTo; newEntity.Description = entry.Description; newEntity.Title = entry.Title; newEntity.UserId = entry.UserId; return(newEntity); }
/// <summary> /// Convert a <see cref="CalendarEventViewModel"/> to a <see cref="CalEventDm"/>. /// </summary> /// <param name="eventVm">The model to convert.</param> /// <returns>The converted <see cref="CalEventDm"/>.</returns> private CalEventDm ConvertCalendarEventViewModelToDomainModel(CalendarEventViewModel eventVm) { var calEvent = new CalEventDm() { CalendarEntryId = eventVm.CalendarEventId, Title = eventVm.Title.Trim(), Description = string.IsNullOrEmpty(eventVm.Description) ? null : eventVm.Description.Trim(), DateFrom = eventVm.DateFrom, DateTo = eventVm.DateTo, AllDay = eventVm.AllDay, UserId = eventVm.UserId }; return(calEvent); }
public void EditCalendarEvent(CalEventDm entry) { // Get the original event. var originalEntry = _context.CalendarEvents.FirstOrDefault(x => x.CalendarEventId == entry.CalendarEntryId); // Double check the event exists. if (originalEntry == null) { throw new Exception("The calendar event could not be found."); } // Update values. originalEntry.Title = entry.Title; originalEntry.Description = entry.Description; originalEntry.DateFrom = entry.DateFrom; originalEntry.DateTo = entry.DateTo; originalEntry.AllDay = entry.AllDay; // Save changes. _context.Entry(originalEntry).State = EntityState.Modified; _context.SaveChanges(); }
/// <summary> /// Create a calendar event in the <see cref="Ical.Net.Calendar"/>. /// </summary> /// <param name="iCal">The calendar to add the event to.</param> /// <param name="entry">The event to add.</param> private void CreateCalendarIcalEventFromCalendarEvent(Ical.Net.Calendar iCal, CalEventDm entry) { // Create event. var evt = iCal.Create <Ical.Net.CalendarComponents.CalendarEvent>(); // Prepare ical event. evt.Uid = entry.CalendarEntryId.ToString(); evt.Start = new Ical.Net.DataTypes.CalDateTime(entry.DateFrom); evt.End = new Ical.Net.DataTypes.CalDateTime(entry.DateTo); evt.Description = entry.Description; evt.Summary = entry.Title; evt.IsAllDay = entry.AllDay; }