public void TestCalendarEvent_CreateWithReminder_ShouldReturnNewEventWithReminder(
            string color,
            string title,
            string description,
            string start,
            string end,
            bool reminderActive,
            string reminderTime,
            ReminderTimeOffset reminderTimeOffset)
        {
            var optionalEndDate = end == null ? default(DateTime?) : DateTime.Parse(end);
            var startDate       = DateTime.Parse(start);
            var expectedEvent   = CalendarEvent.Create(color, title, description, startDate, optionalEndDate)
                                  .WithReminder(Reminder.Create(
                                                    reminderActive,
                                                    DateTime.Parse(reminderTime),
                                                    reminderTimeOffset));

            expectedEvent.Color.Should().Be(color);
            expectedEvent.Title.Should().Be(title);
            expectedEvent.Description.Should().Be(description);
            expectedEvent.Start.Should().Be(startDate);
            expectedEvent.End.Should().Be(optionalEndDate);
            expectedEvent.Reminders.ToArray()[0].Time.Should().Be(DateTime.Parse(reminderTime));
            expectedEvent.Reminders.ToArray()[0].Active.Should().Be(reminderActive);
            expectedEvent.Reminders.ToArray()[0].TimeOffset.Should().Be(reminderTimeOffset);
        }
        public IActionResult Post([FromBody] CalendarEventInputModel item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            // replace with command pattern or builder pattern
            var newItem = CalendarEvent.Create(
                item.Color,
                item.Title,
                item.Description,
                item.Start,
                item.End);

            if (item.Reminders != null)
            {
                newItem.WithReminder(
                    Reminder.Create(
                        item.Reminders.ToArray()[0].Active,
                        item.Reminders.ToArray()[0].Time,
                        item.Reminders.ToArray()[0].TimeOffset));
            }

            _calendarService.Store(newItem);
            return(Ok());
        }
Exemplo n.º 3
0
            public async Task <Result <Contract> > Handle(Contract request, CancellationToken cancellationToken)
            {
                if (request.UserRole == "Student" || request.UserRole == "Secretary" || request.UserRole == "Recruiter")
                {
                    return(Result.Fail <Contract>("Acesso Negado"));
                }

                if (String.IsNullOrEmpty(request.TrackId))
                {
                    return(Result.Fail <Contract>("Id da Trilha não informado"));
                }

                var trackId = ObjectId.Parse(request.TrackId);
                var track   = await _db.TrackCollection.AsQueryable()
                              .Where(t => t.Id == trackId)
                              .FirstOrDefaultAsync();

                if (track == null)
                {
                    return(Result.Fail <Contract>("Trilha não existe"));
                }

                var calEvents = new List <CalendarEvent>();

                foreach (var reqEvent in request.CalendarEvents)
                {
                    var calEvent = CalendarEvent.Create(
                        reqEvent.Title,
                        reqEvent.EventDate,
                        reqEvent.Duration
                        );

                    if (calEvent.IsSuccess)
                    {
                        calEvents.Add(calEvent.Data);
                    }
                }

                track.CalendarEvents = calEvents;

                await _db.TrackCollection.ReplaceOneAsync(t =>
                                                          t.Id == track.Id, track,
                                                          cancellationToken : cancellationToken
                                                          );

                return(Result.Ok(request));
            }
        public void TestCalendarEvent_Create_ShouldReturnNewEvent(
            string color,
            string title,
            string description,
            string start,
            string end = null)
        {
            var optionalEndDate = end == null ? default(DateTime?) : DateTime.Parse(end);
            var startDate       = DateTime.Parse(start);
            var expectedEvent   = CalendarEvent.Create(color, title, description, startDate, optionalEndDate);

            expectedEvent.Color.Should().Be(color);
            expectedEvent.Title.Should().Be(title);
            expectedEvent.Description.Should().Be(description);
            expectedEvent.Start.Should().Be(startDate);
            expectedEvent.End.Should().Be(optionalEndDate);
        }