Ejemplo n.º 1
0
 /// <summary>
 /// Instantiates an instance of <c>Talk</c>
 /// </summary>
 /// <param name="talkId">Unique identity of talk</param>
 /// <param name="title">Title of Talk</param>
 /// <param name="description">Description of talk</param>
 /// <param name="duration">Duration/Length of talk</param>
 /// <param name="startTime">Start time of the talk</param>
 private Talk(TalkId talkId, Title title, Description description, Duration duration, TalkStartTime startTime)
     : base(talkId.Id)
 {
     TalkId      = talkId;
     Title       = title;
     Description = description;
     Duration    = duration;
     StartTime   = startTime;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an instance of <c>StartTime</c>
        /// </summary>
        /// <param name="startTime">Start time</param>
        /// <returns>An instance of <c>StartTime</c></returns>
        public static Result <TalkStartTime> Create(DateTime startTime)
        {
            // start time must be between 9-12 or 1-4PM
            if ((startTime >= MorningSessionStartTime && startTime < MorningSessionEndTime) ||
                (startTime >= AfternoonSessionStartTime && startTime < AfternoonSessionEndTime))
            {
                var startObject = new TalkStartTime(startTime);
                return(SuccessResult <TalkStartTime> .Create(startObject));
            }

            return(InvalidResult <TalkStartTime> .Create("Invalid start time"));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds a talk to a track
        /// </summary>
        /// <param name="talkId">Unique identity of a talk to be added to track</param>
        /// <param name="title">Title of Talk</param>
        /// <param name="description">Description of talk</param>
        /// <param name="duration">Duration/Length of talk</param>
        /// <returns>An instance of <c>Talk</c></returns>
        public Result <Talk> CreateAndAddTalk(TalkId talkId, Title title, Description description, Duration duration)
        {
            var alreadyExistingTalk = _talks.FirstOrDefault(t => t.TalkId == talkId);

            if (alreadyExistingTalk != null)
            {
                return(InvalidResult <Talk> .Create("Talk already added"));
            }

            DateTime startTime;

            if (_nextMorningSession.TimeOfDay.Add(duration.Value) <= _morningSessionEnd.TimeOfDay)
            {
                // Add to morning
                startTime           = _nextMorningSession;
                _nextMorningSession = _nextMorningSession.Add(duration.Value);
            }
            else if (_nextAfternoonSession.TimeOfDay.Add(duration.Value) <= _afternoonSessionEnd.TimeOfDay)
            {
                // Add to afternoon
                startTime             = _nextAfternoonSession;
                _nextAfternoonSession = _nextAfternoonSession.Add(duration.Value);
            }
            else
            {
                return(InvalidResult <Talk> .Create("No slot available in the track for the specified duration"));
            }

            var startTimeResult = TalkStartTime.Create(startTime);

            if (startTimeResult.IsFailure)
            {
                return(InvalidResult <Talk> .Create(startTimeResult.Error.Value.Message));
            }

            var createTalkResult = Talk.Create(talkId, title, description, duration, startTimeResult.Data);

            if (createTalkResult.IsFailure)
            {
                return(InvalidResult <Talk> .Create(createTalkResult.Error.Value.Message));
            }

            _talks.Add(createTalkResult.Data);

            return(SuccessResult <Talk> .Create(createTalkResult.Data));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates an instance of <c>Talk</c>
        /// </summary>
        /// <param name="talkId">Unique identity of talk</param>
        /// <param name="title">Title of Talk</param>
        /// <param name="description">Description of talk</param>
        /// <param name="duration">Duration/Length of talk</param>
        /// <param name="startTime">Start time of the talk</param>
        public static Result <Talk> Create(TalkId talkId, Title title, Description description, Duration duration, TalkStartTime startTime)
        {
            var talk = new Talk(talkId, title, description, duration, startTime);

            return(SuccessResult <Talk> .Create(talk));
        }