예제 #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));
                }
            }
        }
예제 #2
0
        private string addOrUpdateCurrentDay(string date)
        {
            date = Md5Hashing.CreateMD5(date);
            var day = _dayRepository.Get(date);

            if (day == null)
            {
                _dayRepository.Add(new WholeDay(date));
            }

            return(date);
        }