public async Task <Sheet> GetBySubjectAsync(int month, int year, int ownerId)
        {
            Sheet theSheet = await this._sheetRepository.GetByDatePart(month, year, ownerId)
                             .Include(x => x.Owner)
                             .FirstOrDefaultAsync();

            if (theSheet == null)
            {
                theSheet = this.CreateSheet(month, year, ownerId);

                // Even though CalculationOptions shares the table, it is a fully fledged
                // entity and needs to be registered with EF together with the Sheet entity itself.
                this._sheetRepository.Add(theSheet.CalculationOptions);
                this._sheetRepository.Add(theSheet);

                await this._sheetRepository.SaveChangesAsync();
            }
            else
            {
                theSheet.Entries = await this._sheetRepository.GetOfSheet(theSheet).ToListAsync();

                theSheet.ApplicableTemplates = await this._sheetRepository.GetTemplatesOfSheet(theSheet).ToListAsync();
            }

            return(theSheet);
        }
Example #2
0
        private Sheet CreateSheet(int month, int year, int ownerId)
        {
            Sheet sheet = new Sheet();

            sheet.Subject = new DateTime(year, month, 1);
            sheet.Owner   = this._appOwnerRepository.FindById(ownerId).EnsureNotNull(HttpStatusCode.BadRequest);

            return(sheet);
        }
        private Sheet CreateSheet(int month, int year, int ownerId)
        {
            Sheet sheet = new Sheet();

            sheet.Subject = new DateTime(year, month, 1);
            sheet.Owner = this._appOwnerRepository.FindById(ownerId).EnsureNotNull(HttpStatusCode.BadRequest);

            return sheet;
        }
        private Sheet CreateSheet(int month, int year, int ownerId)
        {
            var sheet = new Sheet();

            sheet.Subject             = new DateTime(year, month, 1);
            sheet.Owner               = this._appOwnerRepository.FindById(ownerId).EnsureNotNull(HttpStatusCode.BadRequest);
            sheet.ApplicableTemplates = new List <SheetRecurringSheetEntry>(
                this._recurringSheetEntryRepository.GetByOwner(ownerId).Select(x => SheetRecurringSheetEntry.Create(sheet, x)));

            return(sheet);
        }
Example #5
0
        public Sheet GetBySubject(int month, int year, int ownerId)
        {
            Sheet theSheet = this._sheetRepository.GetByDatePart(month, year, ownerId)
                             .Include(x => x.Entries)
                             .FirstOrDefault();

            if (theSheet == null)
            {
                theSheet = this.CreateSheet(month, year, ownerId);

                this._sheetRepository.Add(theSheet);
                this._sheetRepository.SaveChanges();
            }

            return(theSheet);
        }
        public async Task <PreviousSheetVisitMarker> GetAndUpdateAsync([NotNull] Sheet sheet, int userId)
        {
            if (sheet == null)
            {
                throw new ArgumentNullException(nameof(sheet));
            }

            SheetLastVisitedMarker marker = await this._sheetLastVisitedMarkerRepository.FindAsync(sheet, userId);

            if (marker == null)
            {
                return(PreviousSheetVisitMarker.Empty);
            }

            PreviousSheetVisitMarker previousMarker = PreviousSheetVisitMarker.FromSheetLastVisitMarker(marker);

            // Asynchronously update the marker. This is done asynchronously, because it is very confusing otherwise.
            this._sheetVisitUpdateJob.TriggerUpdate(sheet.Id, userId);

            return(previousMarker);
        }
        public async Task AddOrUpdateImmediateAsync([NotNull] Sheet sheet, int userId)
        {
            if (sheet == null)
            {
                throw new ArgumentNullException(nameof(sheet));
            }

            SheetLastVisitedMarker marker = await this._sheetLastVisitedMarkerRepository.FindAsync(sheet, userId);

            if (marker == null)
            {
                marker = new SheetLastVisitedMarker
                {
                    UserId = userId,
                    Sheet  = sheet,
                };
                this._sheetLastVisitedMarkerRepository.Add(marker);
            }

            marker.LastVisitDate = DateTime.UtcNow;

            await this._sheetLastVisitedMarkerRepository.SaveChangesAsync();
        }