public async Task TryInteract(StorageCellInteractionDto dto) { await Execute(async() => { using (UnitOfWork db = new UnitOfWork()) { StorageCellEntity storageCell = await db.GetRepo <StorageCellEntity>().Get(dto.StorageCellId.Value); AccountEntity account = await db.GetRepo <AccountEntity>().Get(dto.AccountId.Value); StorageCellEventEntity storageCellEvent = new StorageCellEventEntity() { account_id = account.id, storage_cell_id = storageCell.id, timespan = DateTime.Now }; NotPermittedException ex = null; if (account.Roles.SelectMany(r => r.StorageCellPermissions).Any(m => m.id == storageCell.id)) { storageCellEvent.log = $"Interaction with Storage cell #{storageCell.id} by Account #{account.id}: SUCCESS"; } else { storageCellEvent.log = $"Interaction with Storage cell #{storageCell.id} by Account #{account.id}: ACCESS DENIED"; ex = new NotPermittedException(storageCellEvent.log); } await db.GetRepo <StorageCellEventEntity>().Create(storageCellEvent); await db.Save(); if (ex != null) { throw ex; } } }); }
public async Task <HttpResponseMessage> TryInteract([FromBody] StorageCellInteractionDto dto) { return(await Execute(d => StorageCellService.TryInteract(d), dto)); }