Example #1
0
        /// <inheritdoc />
        public async Task <IList <IMeeting> > GetRecentMeetingsMostRecentFirstAsync(
            IWho who,
            TimeSpan timeSpan,
            int maxNumberOfMeetings)
        {
            this.logger.ReportEntry(
                who,
                new
            {
                TimeSpan            = timeSpan,
                MaxNumberOfMeetings = maxNumberOfMeetings
            });

            DateTime           earliestDate = DateTime.Now.Subtract(timeSpan);
            IList <MeetingDto> meetingDtos  = await this.context.Meetings
                                              .AsNoTracking()
                                              .TagWith(this.Tag(who))
                                              .Take(maxNumberOfMeetings)
                                              .Include(m => m.Committee)
                                              .ThenInclude(c => c !.Organisation)
                                              .Where(m => m.MeetingDateTime >= earliestDate)
                                              .ToListAsync()
                                              .ConfigureAwait(false);

            IList <IMeeting> meetings = meetingDtos.Select(m => m.ToDomain()).ToList();

            this.logger.ReportExit(
                who,
                new { Meetings = meetings });

            return(meetings);
        }
Example #2
0
        /// <summary>
        /// Reports the entry into a method.
        /// </summary>
        /// <param name="logger">Logger.</param>
        /// <param name="who">Who details.</param>
        /// <param name="viewName">Name of the View.</param>
        /// <param name="model">View Model.</param>
        /// <param name="statusCode">Status Code.</param>
        /// <param name="className">Name of the class.</param>
        /// <param name="methodName">Name of the method.</param>
        /// <param name="lineNumber">The line number.</param>
        public static void ReportExitView(
            this ILogger logger,
            IWho who,
            string?viewName,
            object?model,
            int?statusCode,
            [CallerFilePath] string className    = "Unknown",
            [CallerMemberName] string methodName = "Unknown",
            [CallerLineNumber] int lineNumber    = 0)
        {
            if (!logger.IsEnabled(LogLevel.Trace))
            {
                return;
            }

            ClassMethod classMethod = new ClassMethod(className, methodName, lineNumber);

            logger.LogTrace(
                ResourceMessageTemplates.ReportExitView,
                "Exit",
                viewName ?? classMethod.MethodName,
                model,
                statusCode,
                who,
                classMethod);
        }
Example #3
0
        /// <summary>
        /// Update Committee.
        /// </summary>
        /// <param name="who">Who Details.</param>
        /// <param name="model">Edit view model.</param>
        /// <returns>Nothing.</returns>
        private async Task UpdateRecordAsync(
            IWho who,
            EditViewModel model)
        {
            this.logger.ReportEntry(
                who,
                new { Model = model });

            ICommittee originalCommittee = await this.service
                                           .GetCommitteeByIdAsync(
                who : who,
                committeeId : model.CommitteeId)
                                           .ConfigureAwait(false);

            ICommittee committee = model.ToDomain(originalCommittee.Organisation);

            await this.service
            .UpdateCommitteeAsync(
                who : who,
                auditEvent : AuditEvent.CommitteeMaintenance,
                committee : committee)
            .ConfigureAwait(false);

            this.logger.ReportExit(who);
        }
Example #4
0
        /// <summary>
        /// Display committees for the specified organisation.
        /// </summary>
        /// <param name="organisationId">The organisation identifier.</param>
        /// <returns>View.</returns>
        public async Task <IActionResult> Index(Guid organisationId)
        {
            IWho who = this.Who();

            this.logger.ReportEntry(
                who,
                new { OrganisationId = organisationId });

            IOrganisationWithCommittees organisation = await this.service
                                                       .GetOrganisationByIdWithCommitteesAsync(
                who : who,
                organisationId : organisationId)
                                                       .ConfigureAwait(false);

            IndexViewModel model = IndexViewModel.Create(organisation);

            ViewResult view = this.View(model);

            this.logger.ReportExitView(
                who,
                view.ViewName,
                view.Model,
                view.StatusCode);

            return(view);
        }
Example #5
0
        public async Task Test_Passing_Null_Organisation_Throws_Exception()
        {
            // ARRANGE
            IWho who = Create.Who();

            Mock <ILogger <IOrganisationService> > loggerMock =
                MockFactory.CreateLoggerMock <IOrganisationService>();

            DbContextOptions <DataContext> dbOptions =
                TestUtils.DbContextOptionsInMemory <CreateAsyncTests>(
                    nameof(this.Test_Passing_Valid_Values));

            await using DataContext dataContext = new DataContext(dbOptions);

            IVirtualBridgeData data =
                MockFactory.CreateVirtualBridgeData(
                    dataContext);

            IOrganisationService service = new OrganisationService(
                loggerMock.Object,
                data);

            // ACT
            await service.CreateAsync(
                who : who,
                auditEvent : EAuditEvent.OrganisationMaintenance,
                organisation : null !)
            .ConfigureAwait(false);
        }
Example #6
0
        /// <summary>
        /// Display the specified Meeting.
        /// </summary>
        /// <param name="meetingId">Meeting Id.</param>
        /// <returns>View.</returns>
        public async Task <IActionResult> Index(Guid meetingId)
        {
            IWho who = this.Who();

            this.logger.ReportEntry(
                who,
                new { MeetingId = meetingId });

            IMeeting meeting = await this.service
                               .GetMeetingByIdAsync(
                who : who,
                meetingId : meetingId)
                               .ConfigureAwait(false);

            IndexViewModel model = IndexViewModel.Create(meeting);

            ViewResult view = this.View(model);

            this.logger.ReportExitView(
                who,
                view.ViewName,
                view.Model,
                view.StatusCode);

            return(view);
        }
Example #7
0
        /// <inheritdoc/>
        public async Task <IList <IMeeting> > GetRecentMeetingsMostRecentFirstAsync(
            IWho who,
            TimeSpan?timeSpan       = null,
            int?maxNumberOfMeetings = null)
        {
            this.logger.ReportEntry(
                who,
                new
            {
                TimeSpan            = timeSpan,
                MaxNumberOfMeeeting = maxNumberOfMeetings
            });

            IList <IMeeting> meetings = await this.data
                                        .GetRecentMeetingsMostRecentFirstAsync(
                who : who,
                timeSpan : timeSpan ?? TimeSpan.FromDays(365),
                maxNumberOfMeetings : maxNumberOfMeetings ?? 20)
                                        .ConfigureAwait(false);

            this.logger.ReportExit(
                who,
                new { Meetings = meetings });

            return(meetings);
        }
Example #8
0
        /// <summary>
        /// Reports the entry into a method.
        /// </summary>
        /// <param name="logger">Logger.</param>
        /// <param name="who">Who details.</param>
        /// <param name="controllerName">Name of the Controller.</param>
        /// <param name="actionName">Name of the Action.</param>
        /// <param name="model">View Model.</param>
        /// <param name="className">Name of the class.</param>
        /// <param name="methodName">Name of the method.</param>
        /// <param name="lineNumber">The line number.</param>
        public static void ReportExitRedirectToAction(
            this ILogger logger,
            IWho who,
            string?controllerName,
            string?actionName,
            object?model,
            [CallerFilePath] string className    = "Unknown",
            [CallerMemberName] string methodName = "Unknown",
            [CallerLineNumber] int lineNumber    = 0)
        {
            if (!logger.IsEnabled(LogLevel.Trace))
            {
                return;
            }

            ClassMethod classMethod = new ClassMethod(className, methodName, lineNumber);

            logger.LogTrace(
                ResourceMessageTemplates.ReportExitRedirectToAction,
                "Exit",
                controllerName ?? classMethod.ClassName,
                actionName ?? classMethod.MethodName,
                model,
                who,
                classMethod);
        }
Example #9
0
        /// <inheritdoc/>
        public async Task <IOrganisationWithCommittees> GetOrganisationByIdWithCommitteesAsync(
            IWho who,
            Guid organisationId)
        {
            this.logger.ReportEntry(
                who,
                new { OrganisationId = organisationId });

            IOrganisationWithCommittees organisationWithCommittees = (await this.context.Organisations
                                                                      .AsNoTracking()
                                                                      .TagWith(this.Tag(who))
                                                                      .Include(o => o.Committees)
                                                                      .FirstOrDefaultAsync(o => o.Id == organisationId)
                                                                      .ConfigureAwait(false))
                                                                     .ToDomainWithCommittees();

            this.logger.ReportExit(
                who,
                new
            {
                OrganisationWithCommittees = organisationWithCommittees
            });

            return(organisationWithCommittees);
        }
Example #10
0
        /// <inheritdoc/>
        public async Task UpdateMeetingAsync(
            IWho who,
            AuditEvent auditEvent,
            IMeeting meeting)
        {
            this.logger.ReportEntry(
                who,
                new { Meeting = meeting });

            try
            {
                IAuditHeaderWithAuditDetails auditHeader = this.data.BeginTransaction(auditEvent, who);

                await this.data
                .UpdateMeetingAsync(
                    who : who,
                    auditHeader : auditHeader,
                    meeting : meeting)
                .ConfigureAwait(false);

                await this.data.CommitTransactionAsync(auditHeader)
                .ConfigureAwait(false);
            }
            catch (Exception)
            {
                this.data.RollbackTransaction();
                throw;
            }

            this.logger.ReportExit(who);
        }
Example #11
0
        /// <summary>
        /// Log an error message.
        /// </summary>
        /// <param name="logger">Logger.</param>
        /// <param name="who">Who details.</param>
        /// <param name="message">Error message.</param>
        /// <param name="data">Relevant data.</param>
        /// <param name="className">Name of the class.</param>
        /// <param name="methodName">Name of the method.</param>
        /// <param name="lineNumber">The line number.</param>
        public static void Error(
            this ILogger logger,
            IWho who,
            string message,
            object?data = null,
            [CallerFilePath] string className    = "Unknown",
            [CallerMemberName] string methodName = "Unknown",
            [CallerLineNumber] int lineNumber    = 0)
        {
            if (!logger.IsEnabled(LogLevel.Error))
            {
                return;
            }

            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            ClassMethod classMethod = new ClassMethod(className, methodName, lineNumber);

            logger.LogDebug(
                ResourceMessageTemplates.Error,
                message,
                data,
                who,
                classMethod);
        }
Example #12
0
        /// <summary>
        /// SOMETHING.
        /// </summary>
        /// <param name="meetingId">Meeting Id.</param>
        /// <returns>Action Result.</returns>
        public async Task <IActionResult> Index(Guid meetingId)
        {
            IWho who = this.Who();

            this.logger.ReportEntry(
                who,
                new { MeetingId = meetingId });

            IMeeting meeting = await this.service.GetMeetingByIdAsync(
                who,
                meetingId).ConfigureAwait(false);

            IAgendaItem agendaItem = await this.service.GetAgendaItemsByMeetingIdAsTreeAsync(
                who,
                meetingId).ConfigureAwait(false);

            if (agendaItem == null)
            {
                agendaItem = await this.service.CreateSkeletonAgendaAsync(
                    who,
                    AuditEvent.ViewAgenda,
                    meetingId,
                    SkeletonAgendaType.BasicContinuation).ConfigureAwait(false);
            }

            _ = meeting;
            _ = agendaItem;

            throw new NotImplementedException();
            ////return this.View();
        }
        /// <summary>
        /// Display meetings for the specified committee.
        /// </summary>
        /// <param name="committeeId">CommitteeId.</param>
        /// <returns>View.</returns>
        public async Task <IActionResult> Index(Guid committeeId)
        {
            IWho who = this.Who();

            this.logger.ReportEntry(
                who,
                new { CommitteeId = committeeId });

            ICommitteeWithMeetings committee = await this.service
                                               .GetCommitteeByIdWithMeetingsAsync(
                who : who,
                committeeId : committeeId)
                                               .ConfigureAwait(false);

            IndexViewModel model = IndexViewModel.Create(committee);

            ViewResult view = this.View(model);

            this.logger.ReportExitView(
                who,
                view.ViewName,
                view.Model,
                view.StatusCode);

            return(view);
        }
Example #14
0
        /// <inheritdoc />
        public Task <IList <IOrganisation> > GetAllAsync(IWho who)
        {
            if (who == null)
            {
                throw new ArgumentNullException(nameof(who));
            }

            return(GetAllAsyncInternal());

            async Task <IList <IOrganisation> > GetAllAsyncInternal()
            {
                this.logger.LogTrace(
                    "ENTRY {Method}(who, organisation) {@Who}",
                    nameof(this.GetAllAsync),
                    who);

                IList <IOrganisation> organisations = await this.data.Organisation.GetAllAsync(
                    who : who)
                                                      .ConfigureAwait(false);

                this.logger.LogTrace(
                    "EXIT {Method}(who, organisations) {@Who} {@Organisations}",
                    nameof(this.GetAllAsync),
                    who);

                return(organisations);
            }
        }
Example #15
0
        /// <inheritdoc/>
        public async Task UpdateOrganisationAsync(
            IWho who,
            AuditEvent auditEvent,
            IOrganisation organisation)
        {
            this.logger.ReportEntry(
                who,
                new { Organisation = organisation });

            try
            {
                IAuditHeaderWithAuditDetails auditHeader = this.data.BeginTransaction(auditEvent, who);

                await this.data
                .UpdateOrganisationAsync(
                    who : who,
                    auditHeader : auditHeader,
                    organisation : organisation)
                .ConfigureAwait(false);

                await this.data.CommitTransactionAsync(auditHeader)
                .ConfigureAwait(false);
            }
            catch (Exception)
            {
                this.data.RollbackTransaction();
                throw;
            }

            this.logger.ReportExit(who);
        }
Example #16
0
        public async Task <IActionResult> Index()
        {
            IWho who = this.Who();

            this.logger.ReportEntry(who);

            IList <IMeeting> meetings = await this.service
                                        .GetRecentMeetingsMostRecentFirstAsync(who)
                                        .ConfigureAwait(false);

            ISetupStatus setupStatus = meetings.Any()
                ? new SetupStatus(haveOrganisations: true, haveCommittees: true)
                : await this.service
                                       .GetSetupStatusAsync(who)
                                       .ConfigureAwait(false);

            bool featureEnabled = await this.featureManager
                                  .IsEnabledAsync(nameof(FeatureFlag.NewReferenceSearch))
                                  .ConfigureAwait(false);

            IndexViewModel model = IndexViewModel.Create(meetings, setupStatus, featureEnabled);

            ViewResult view = this.View(model);

            this.logger.ReportExitView(
                who,
                view.ViewName,
                view.Model,
                view.StatusCode);

            return(view);
        }
Example #17
0
        /// <inheritdoc/>
        public async Task UpdateAsync(
            IWho who,
            IAuditHeaderWithAuditDetails auditHeader,
            ICompetition competition)
        {
            this.logger.LogTrace(
                "ENTRY {Method}(who, host) {@Who} {@Competition}",
                nameof(this.UpdateAsync),
                who,
                competition);

            CompetitionDto dto      = CompetitionDto.ToDto(competition);
            CompetitionDto original = await this.context.FindAsync <CompetitionDto>(competition.Id)
                                      .ConfigureAwait(false);

            Audit.AuditUpdate(auditHeader, dto.Id, original, dto);

            this.context.Entry(original).CurrentValues.SetValues(dto);
            await this.context.SaveChangesAsync().ConfigureAwait(false);

            this.logger.LogTrace(
                "EXIT {Method}(who) {@Who}",
                nameof(this.UpdateAsync),
                who);
        }
Example #18
0
        /// <inheritdoc/>
        public async Task CreateCommitteeAsync(
            IWho who,
            AuditEvent auditEvent,
            ICommittee committee)
        {
            this.logger.ReportEntry(
                who,
                new { Committee = committee });

            try
            {
                IAuditHeaderWithAuditDetails auditHeader = this.data.BeginTransaction(auditEvent, who);

                await this.data.CreateCommitteeAsync(
                    who : who,
                    auditHeader : auditHeader,
                    committee : committee)
                .ConfigureAwait(false);

                await this.data.CommitTransactionAsync(auditHeader)
                .ConfigureAwait(false);
            }
            catch (Exception)
            {
                this.data.RollbackTransaction();
                throw;
            }

            this.logger.ReportExit(who);
        }
Example #19
0
        /// <inheritdoc/>
        public async Task <ISetupStatus> GetSetupStatusAsync(IWho who)
        {
            this.logger.ReportEntry(who);

            bool haveOrganisations = await this.data
                                     .HaveOrganisationsAsync(who)
                                     .ConfigureAwait(false);

            SetupStatus setupStatus;

            if (!haveOrganisations)
            {
                setupStatus = new SetupStatus(
                    haveOrganisations: false,
                    haveCommittees: false);
            }
            else
            {
                bool haveCommittees = await this.data
                                      .HaveCommitteesAsync(who)
                                      .ConfigureAwait(false);

                setupStatus = new SetupStatus(
                    haveOrganisations: true,
                    haveCommittees: haveCommittees);
            }

            this.logger.ReportExit(
                who,
                new { SetupStatus = setupStatus });

            return(setupStatus);
        }
Example #20
0
        /// <inheritdoc/>
        public async Task CreateAgendaItemRecursivelyAsync(
            IWho who,
            IAuditHeaderWithAuditDetails auditHeader,
            IAgendaItem agendaItem)
        {
            AgendaItemDto dto = AgendaItemDto.ToDto(agendaItem);

            this.context.AgendaItems.Add(dto);
            Audit.AuditCreate(auditHeader, dto, dto.Id);

            foreach (IAgendaItem child in agendaItem.ChildAgendaItems)
            {
                await this.CreateAgendaItemRecursivelyAsync(
                    who,
                    auditHeader,
                    child);
            }

            if (agendaItem.ParentId == null)
            {
                this.logger.Debug(
                    who,
                    "Saving changes",
                    new { AgendaItemId = agendaItem });
                await this.context.SaveChangesAsync();
            }

            this.logger.ReportExit(who);
        }
Example #21
0
        /// <summary>
        /// Update Meeting.
        /// </summary>
        /// <param name="who">Who Details.</param>
        /// <param name="model">Edit view model.</param>
        /// <returns>Nothing.</returns>
        private async Task UpdateRecordAsync(
            IWho who,
            EditViewModel model)
        {
            this.logger.ReportEntry(
                who,
                new { Model = model });

            IMeeting originalMeeting = await this.service
                                       .GetMeetingByIdAsync(
                who : who,
                meetingId : model.MeetingId)
                                       .ConfigureAwait(false);

            IMeeting meeting = model.ToDomain(
                committee: originalMeeting.Committee);

            await this.service
            .UpdateMeetingAsync(
                who : who,
                auditEvent : AuditEvent.MeetingMaintenance,
                meeting : meeting)
            .ConfigureAwait(false);

            this.logger.ReportExit(who);
        }
Example #22
0
 public Context(IWho who, IWhat what, IWhere where, IWhen when, IWhy why)
 {
     Who   = who;
     What  = what;
     Where = where;
     When  = when;
     Why   = why;
 }
Example #23
0
        /// <summary>
        /// Adds this instance.
        /// </summary>
        /// <param name="model">Add view model.</param>
        /// <returns>View.</returns>
        public Task <IActionResult> Add(AddViewModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            return(Internal());

            async Task <IActionResult> Internal()
            {
                IWho who = this.Who();

                this.logger.ReportEntry(
                    who,
                    new { Model = model });

                if (model.FormState == FormState.Initial)
                {
                    this.ModelState.Clear();
                }
                else
                {
                    if (this.ModelState.IsValid)
                    {
                        this.logger.Debug(
                            who,
                            "Inserting model",
                            new { Model = model });

                        await this.InsertRecordAsync(who, model).ConfigureAwait(false);

                        RedirectToActionResult redirect = this.RedirectToAction(
                            "Index",
                            "MeetingOverview",
                            new { committeeId = model.CommitteeId });

                        this.logger.ReportExitRedirectToAction(
                            who,
                            redirect.ControllerName,
                            redirect.ActionName,
                            redirect.RouteValues);

                        return(redirect);
                    }
                }

                ViewResult view = this.View(model);

                this.logger.ReportExitView(
                    who,
                    view.ViewName,
                    view.Model,
                    view.StatusCode);

                return(view);
            }
        }
Example #24
0
        public Task <IActionResult> Add(AddViewModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            return(Internal());

            async Task <IActionResult> Internal()
            {
                IWho who = this.Who();

                this.logger.ReportEntry(
                    who,
                    new { Model = model });

                if (model.FormState == FormState.Initial)
                {
                    model = new AddViewModel(
                        formState: FormState.Initial,
                        code: string.Empty,
                        name: string.Empty,
                        bgColour: string.Empty);
                    this.ModelState.Clear();
                }
                else
                {
                    if (this.ModelState.IsValid)
                    {
                        await this.InsertRecordAsync(who, model).ConfigureAwait(false);

                        RedirectToActionResult redirect = this.RedirectToAction("Index", "OrganisationOverview");

                        this.logger.ReportExitRedirectToAction(
                            who,
                            redirect.ControllerName,
                            redirect.ActionName,
                            redirect.RouteValues);

                        return(redirect);
                    }
                }

                ViewResult view = this.View(model);

                this.logger.ReportExitView(
                    who,
                    view.ViewName,
                    view.Model,
                    view.StatusCode);

                return(view);
            }
        }
Example #25
0
        /// <summary>
        /// Returns tag for use with .TagWith().
        /// </summary>
        /// <param name="who">Who details.</param>
        /// <param name="methodName">Method Name.</param>
        /// <returns>Tag.</returns>
        protected string Tag(IWho who, string methodName)
        {
            if (who == null)
            {
                throw new ArgumentNullException(nameof(who));
            }

            string username = "******";

            return($"{this.repositoryName}.{methodName}.{who.CorrelationId}.{username}");
        }
Example #26
0
        public async Task Test_Commit_Writes_Record()
        {
            // ARRANGE
            Mock <ILogger <VirtualBridgeData> > loggerMock =
                MockFactory.CreateLoggerMock <VirtualBridgeData>();
            Mock <ILogger <AuditHeaderRepository> > auditHeaderRepositoryLoggerMock =
                MockFactory.CreateLoggerMock <AuditHeaderRepository>();
            DbContextOptions <DataContext> dbOptions =
                TestUtils.DbContextOptionsInMemory <TestBeginCommit>(
                    nameof(this.Test_Commit_Writes_Record));

            await using DataContext dataContext = new DataContext(dbOptions);
            AuditHeaderRepository auditHeaderRepository = new AuditHeaderRepository(
                logger: auditHeaderRepositoryLoggerMock.Object,
                dataContext: dataContext);
            Mock <IOrganisationRepository> organisationRepositoryMock
                = MockFactory.CreateRepositoryMock <IOrganisationRepository>();

            VirtualBridgeData data = new VirtualBridgeData(
                logger: loggerMock.Object,
                dataContext: dataContext,
                auditHeaderRepository: auditHeaderRepository,
                organisationRepository: organisationRepositoryMock.Object);

            IWho who = Create.Who();

            // ACT
            IAuditHeaderWithAuditDetails auditHeader = await data.BeginTransactionAsync(
                who : who,
                auditEvent : EAuditEvent.OrganisationMaintenance)
                                                       .ConfigureAwait(false);

            auditHeader.AuditDetails.Add(
                AuditDetail.CreateForCreate(
                    auditHeader: auditHeader,
                    tableName: "Organisation",
                    columnName: "Name",
                    recordId: Guid.NewGuid(),
                    newValue: "NewValue"));

            await data.CommitTransactionAsync(who, auditHeader)
            .ConfigureAwait(false);

            // ASSERT
            int auditHeadersCount = await dataContext.AuditHeaders.CountAsync()
                                    .ConfigureAwait(false);

            int auditDetailsCount = await dataContext.AuditDetails.CountAsync()
                                    .ConfigureAwait(false);

            Assert.AreEqual(1, auditHeadersCount);
            Assert.AreEqual(1, auditDetailsCount);
        }
 /// <inheritdoc />
 public Task CreateOrganisationAsync(
     IWho who,
     EAuditEvent auditEvent,
     IOrganisation organisation)
 {
     return(OrganisationHelper.CreateOrganisationAsync(
                logger: this.logger,
                data: this.data,
                who: who,
                auditEvent: auditEvent,
                organisation: organisation));
 }
Example #28
0
        /// <inheritdoc />
        public Task CreateAsync(
            IWho who,
            EAuditEvent auditEvent,
            IOrganisation organisation)
        {
            if (who == null)
            {
                throw new ArgumentNullException(nameof(who));
            }

            if (organisation == null)
            {
                throw new ArgumentNullException(nameof(organisation));
            }

            return(CreateOrganisationInternalAsync());

            async Task CreateOrganisationInternalAsync()
            {
                this.logger.LogTrace(
                    "ENTRY {Method}(who, organisation) {@Who} {@Organisation}",
                    nameof(this.CreateAsync),
                    who,
                    organisation);

                try
                {
                    IAuditHeaderWithAuditDetails auditHeader = await this.data.BeginTransactionAsync(
                        who, auditEvent)
                                                               .ConfigureAwait(false);

                    await this.data.Organisation.CreateAsync(
                        who : who,
                        auditHeader : auditHeader,
                        organisation : organisation)
                    .ConfigureAwait(false);

                    await this.data.CommitTransactionAsync(who, auditHeader)
                    .ConfigureAwait(false);
                }
                catch (Exception)
                {
                    this.data.RollbackTransaction(who);
                    throw;
                }

                this.logger.LogTrace(
                    "EXIT {Method}(who) {@Who}",
                    nameof(this.CreateAsync),
                    who);
            }
        }
Example #29
0
        private string Tag(
            IWho who,
            [CallerMemberName] string methodName = "Unknown")
        {
            if (who == null)
            {
                throw new ArgumentNullException(nameof(who));
            }

            string username = who.Username ?? who.ClientIpAddress;

            return($"{this.GetType().Name}.{methodName}.{who.CorrelationId}.{username}");
        }
Example #30
0
        public IAuditHeaderWithAuditDetails BeginTransaction(AuditEvent auditEvent, IWho who)
        {
            if (who == null)
            {
                throw new ArgumentNullException(nameof(who));
            }

            this.context.Database.BeginTransaction();

            return(new AuditHeaderWithAuditDetails(
                       auditEvent: auditEvent,
                       username: who.Username ?? who.ClientIpAddress,
                       correlationId: who.CorrelationId));
        }