public async Task <IApplicationResult> UpdateStateAsync(Guid id, InventionStateDto dto) { return(await ExecuteAsync(async() => { var isAdmin = await _roleService.IsAdminAsync(_inventAppContext.UserEmail); if (!isAdmin) { throw new UnauthorizedAccessException($"Access Denied. Check permissions for User '{_inventAppContext.UserEmail}'"); } var aggregate = await _unitOfWork.Inventions.GetByIdAsync(id); if (aggregate == null) { throw new ObjectNotFoundException($"Entry with Id={id} not found"); } aggregate.Enable = dto.Enable; await _unitOfWork.Inventions.UpdateAsync(aggregate); _auditService.AuditAsync(new Audit { Application = "InventApp", Environment = _appSettingsService.Environment.Name, User = _inventAppContext.UserEmail, EntityId = aggregate.Id.ToString(), EntityName = aggregate.GetType().Name, Entity = JsonConvert.SerializeObject(aggregate), Action = AuditAction.Update }); return new OkEmptyResult(); })); }
public async Task <IHttpActionResult> UpdateStateAsync([FromUri] Guid id, [FromBody] InventionStateDto dto) => await ExecuteAsync(async() => await _inventionService.UpdateStateAsync(id, dto));