예제 #1
0
        public bool HandlePostProjectEntry(CreateProjectEntryModel newEntry, bool?externalEntry = false)
        {
            bool         result = true;
            ProjectEntry DbProjectEntry;

            if (externalEntry == true)
            {
                DbProjectEntry = CreateProjectEntry(newEntry.StartDate, newEntry);
                return(_projectEntryRepository.PostProjectEntry(DbProjectEntry));
            }

            if (!newEntry.Recurrence)
            {
                return(CreateEntriesWithSplitHours(newEntry));
            }

            var startDate = newEntry.StartDate;
            var endDate   = newEntry.EndDate;

            var days = Enumerable.Range(0, 1 + endDate.Subtract(startDate).Days)
                       .Select(offset => startDate.AddDays(offset))
                       .ToList();

            if (days.Count > 1)
            {
                if (newEntry.RepeatMonday)
                {
                    result = RepeatPostProjectEntry(days,
                                                    DayOfWeek.Monday,
                                                    newEntry);
                }

                if (newEntry.RepeatTuesday)
                {
                    result = RepeatPostProjectEntry(days,
                                                    DayOfWeek.Tuesday,
                                                    newEntry);
                }

                if (newEntry.RepeatWednesday)
                {
                    result = RepeatPostProjectEntry(days,
                                                    DayOfWeek.Wednesday,
                                                    newEntry);
                }

                if (newEntry.RepeatThursday)
                {
                    result = RepeatPostProjectEntry(days,
                                                    DayOfWeek.Thursday,
                                                    newEntry);
                }

                if (newEntry.RepeatFriday)
                {
                    result = RepeatPostProjectEntry(days,
                                                    DayOfWeek.Friday,
                                                    newEntry);
                }
            }
            else
            {
                if (checkHoursForWeek(newEntry.StartDate, newEntry))
                {
                    DbProjectEntry = CreateProjectEntry(newEntry.StartDate.Add(DateTime.Now.TimeOfDay), newEntry);
                    result         = _projectEntryRepository.PostProjectEntry(DbProjectEntry);
                }
            }

            return(result);
        }