public async Task TryInteract(PipelineItemInteractionDto dto)
        {
            await Execute(async() => {
                using (UnitOfWork db = new UnitOfWork())
                {
                    PipelineItemEntity pipelineItem = await db.GetRepo <PipelineItemEntity>().Get(dto.PipelineItemId.Value);
                    AccountEntity account           = await db.GetRepo <AccountEntity>().Get(dto.AccountId.Value);

                    PipelineItemInteractionEventEntity pipelineItemEvent = new PipelineItemInteractionEventEntity()
                    {
                        account_id       = account.id,
                        pipeline_item_id = pipelineItem.id,
                        timespan         = DateTime.Now
                    };

                    NotPermittedException ex = null;

                    if (account.Roles.SelectMany(r => r.PipelineItemPermissions).Any(m => m.id == pipelineItem.id))
                    {
                        pipelineItemEvent.log = $"Interaction with Pipeline item #{pipelineItem.id} by Account #{account.id}: SUCCESS";
                    }
                    else
                    {
                        pipelineItemEvent.log = $"Interaction with Pipeline item #{pipelineItem.id} by Account #{account.id}: ACCESS DENIED";
                        ex = new NotPermittedException(pipelineItemEvent.log);
                    }

                    await db.GetRepo <PipelineItemInteractionEventEntity>().Create(pipelineItemEvent);
                    await db.Save();

                    if (ex != null)
                    {
                        throw ex;
                    }
                }
            });
        }
示例#2
0
 public async Task <HttpResponseMessage> TryInteract([FromBody] PipelineItemInteractionDto dto)
 {
     return(await Execute(d => PipelineItemService.TryInteract(d), dto));
 }