Exemplo n.º 1
0
            public Boolean Resolve(
                SheetEntry source,
                Models.DTO.SheetEntry destination,
                bool destMember,
                ResolutionContext context
                )
            {
                PreviousSheetVisitMarker marker = context.GetPreviousSheetVisitMarker();

                return(source.UpdateTimestamp > marker.LastVisitDate);
            }
Exemplo n.º 2
0
        public async Task <SheetDTO> GetBySubject(int month, int year)
        {
            Sheet theSheet = await this._sheetRetrievalService.GetBySubjectAsync(month, year, this.OwnerId);

            PreviousSheetVisitMarker marker = await this._sheetLastVisitedMarkerService.GetAndUpdateAsync(theSheet, this.User.Identity.GetUserId());

            SheetDTO dto = this._mappingEngine.Map <Sheet, SheetDTO>(theSheet, opts => opts.SetPreviousSheetVisitMarker(marker));

            Array.Sort(dto.Entries, SortOrderComparer <SheetEntry> .Instance);
            return(dto);
        }
        public async Task <SheetEntryDTO> Get(int id, int sheetYear, int sheetMonth)
        {
            Sheet targetSheet = await this._sheetRetrievalService.GetBySubjectAsync(sheetMonth, sheetYear, this.OwnerId).EnsureNotNull();

            this.EntityOwnerService.EnsureOwner(targetSheet, this.OwnerId);

            SheetEntry entry = await this._sheetEntryRepository.FindByIdAsync(id).EnsureNotNull();

            this.EnsureCorrectSheet(entry);

            PreviousSheetVisitMarker marker = await this._sheetLastVisitedMarkerService.GetAndUpdateAsync(targetSheet, this.User.Identity.GetUserId());

            return(this._mappingEngine.Map <SheetEntry, SheetEntryDTO>(entry, opts => opts.SetPreviousSheetVisitMarker(marker)));
        }
Exemplo n.º 4
0
        public async Task <SheetDTO> GetById(int id)
        {
            Sheet sheet = await this._sheetRepository.FindByIdInclude(id).FirstOrDefaultAsync().EnsureNotNull();

            sheet.Entries = new List <Models.Domain.SheetEntry>(this._sheetRepository.GetOfSheet(sheet));

            PreviousSheetVisitMarker marker = await this._sheetLastVisitedMarkerService.GetAndUpdateAsync(sheet, this.User.Identity.GetUserId());

            this.EntityOwnerService.EnsureOwner(sheet, this.OwnerId);
            SheetDTO dto = this._mappingEngine.Map <Sheet, SheetDTO>(sheet, m => m.SetPreviousSheetVisitMarker(marker));

            Array.Sort(dto.Entries, SortOrderComparer <SheetEntry> .Instance);

            return(dto);
        }
        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 static void SetPreviousSheetVisitMarker(
            [NotNull] this IMappingOperationOptions <SheetEntry, SheetEntryDTO> mappingOperationOptions,
            [NotNull] PreviousSheetVisitMarker marker
            )
        {
            if (mappingOperationOptions == null)
            {
                throw new ArgumentNullException(nameof(mappingOperationOptions));
            }
            if (marker == null)
            {
                throw new ArgumentNullException(nameof(marker));
            }

            try
            {
                mappingOperationOptions.Items.Add(SheetLastVisitedMarkerKey, marker);
            }
            catch (ArgumentException ex)
            {
                throw new InvalidOperationException($"{nameof(SetPreviousSheetVisitMarker)} has been called earlier", ex);
            }
        }