Beispiel #1
0
        public ActionResult <Day> Add(DayDTO model)
        {
            Day day = _dayRepository.GetByWeekAndDay(model.TemplateName, model.WeekNr, model.DayNr);

            if (day != null)
            {
                return(BadRequest("A day with this weekNr and dayNr already exists for this template"));
            }
            else
            {
                try
                {
                    Day      dayToAdd       = new Day(model.TemplateName, model.WeekNr, model.DayNr);
                    Activity activitySick   = _activityRepository.GetAllIncludingSickAbsent().SingleOrDefault(a => a.ActivityType == ActivityType.ZIEK);
                    Activity activityAbsent = _activityRepository.GetAllIncludingSickAbsent().SingleOrDefault(a => a.ActivityType == ActivityType.AFWEZIG);
                    dayToAdd.AddDayActivity(new DayActivity(dayToAdd, activitySick, TimeOfDay.VOLLEDIG));
                    dayToAdd.AddDayActivity(new DayActivity(dayToAdd, activityAbsent, TimeOfDay.VOLLEDIG));
                    _dayRepository.Add(dayToAdd);
                    _dayRepository.SaveChanges();
                    return(Ok(dayToAdd));
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Message));
                }
            }
        }
Beispiel #2
0
        public void DayActivity_DayWithNoDayActivitesAndNoHelpers_AddsDayActivity()
        {
            var length = _dayWithNoDayActivitesAndNoHelpers.DayActivities.Count;

            _dayWithNoDayActivitesAndNoHelpers.AddDayActivity(_dummyDBContext.DayActivity12);
            _dayWithNoDayActivitesAndNoHelpers.AddDayActivity(_dummyDBContext.DayActivity10);
            _dayWithNoDayActivitesAndNoHelpers.AddDayActivity(_dummyDBContext.DayActivity11);

            Assert.NotEmpty(_dayWithNoDayActivitesAndNoHelpers.DayActivities);
            Assert.Equal(length + 3, _dayWithNoDayActivitesAndNoHelpers.DayActivities.Count);
        }
Beispiel #3
0
        public ActionResult <DayActivity> AddActivity(string templateName, int weekNr, int dayNr, DayActivityDTO model)
        {
            Day         dayToEdit        = _dayRepository.GetByWeekAndDay(templateName, weekNr, dayNr);
            Activity    activity         = _activityRepository.GetById(model.ActivityId);
            DayActivity dayActivityToAdd = new DayActivity(dayToEdit, activity, model.TimeOfDay);

            dayToEdit.AddDayActivity(dayActivityToAdd);
            _dayRepository.SaveChanges();
            return(dayActivityToAdd);
        }