Ejemplo n.º 1
0
        public async Task <DailyActivityReportDTO> CreateDailyActivityReportAsync(int postId)
        {
            var post = await _postRepository.Find(postId);

            var report = new DailyActivityReport
            {
                Date    = DateTime.Now,
                Post    = post,
                Entries = new List <Entry>()
            };

            _darRepository.Add(report);

            if (await _darRepository.SaveAll())
            {
                var reportToReturn = _mapper.Map <DailyActivityReportDTO>(report);

                return(reportToReturn);
            }

            throw new ApplicationException("Something went wrong creating a new report.");
        }
Ejemplo n.º 2
0
        private async Task <DailyActivityReportDTO> AddEntryToDailyActivityReportAndUpdate(Entry entry, DailyActivityReport dar, Entry parent = null)
        {
            entry.ParentEntry         = parent;
            entry.DailyActivityReport = dar;

            if (entry.OccuranceDate == null)
            {
                entry.OccuranceDate = DateTime.Now;
            }

            if (parent == null)
            {
                dar.Entries.Add(entry);
            }
            else
            {
                parent.ChildEntries.Add(entry);
            }

            _entryRepository.Add(entry);

            if (!await _entryRepository.SaveAll())
            {
                throw new ApplicationException("Something went wrong saving the entry to the database.");
            }

            var entries = await _entryRepository
                          .FindRange(x => x.ParentEntry == null && x.DailyActivityReportId == dar.Id);

            var darToReturn = _mapper.Map <DailyActivityReportDTO>(dar);
            var darEntries  = _mapper.Map <ICollection <EntryDTO> >(entries);

            darToReturn.Entries = darEntries;

            return(darToReturn);
        }