public async Task <NoteCatalog> UpdateAsync(NoteCatalog entity) { Guard.Against <ArgumentNullException>(entity == null, nameof(entity)); // ReSharper disable once PossibleNullReferenceException if (entity.Id <= 0) { ProcessMessage.Success = false; ProcessMessage.AddErrorMessage($"Can not update NoteCatalog with id {entity.Id}", true); return(null); } try { // check if need apply default render var render = PropertyChecking(entity.Render); const string message = "Cannot find default note render."; ProcessMessage.Success = false; ProcessMessage.AddErrorMessage(message, true); entity.Render = render ?? throw new DataSourceException(message); DataContext.Catalogs.Update(entity); await DataContext.SaveAsync(); var newCatalog = await LookupRepo.GetEntityAsync <NoteCatalog>(entity.Id); return(newCatalog); } catch (Exception ex) { ProcessMessage.WrapException(ex); return(null); } }
/// <summary> /// The asynchronous version of <see cref="GetNotes"/> /// </summary> /// <param name="entity">The entity which used to get type and figure out the catalog</param> /// <param name="resourceCollectionParameters">The page information of the resource collection</param> /// <returns>The notes which belongs to entity type</returns> protected async Task <PageList <HmmNote> > GetNotesAsync(T entity, Expression <Func <HmmNote, bool> > query = null, ResourceCollectionParameters resourceCollectionParameters = null) { var catId = await entity.GetCatalogIdAsync(LookupRepo); var author = await LookupRepo.GetEntityAsync <Author>(DefaultAuthor.Id); var hasValidAuthor = DefaultAuthor != null && author != null; switch (hasValidAuthor) { case false: ProcessResult.AddErrorMessage("Cannot find default author", true); return(null); default: PageList <HmmNote> notes; if (query != null) { var finalExp = query.And(n => n.Author.Id == DefaultAuthor.Id && n.Catalog.Id == catId); notes = await NoteManager.GetNotesAsync(finalExp, false, resourceCollectionParameters); } else { notes = await NoteManager.GetNotesAsync(n => n.Author.Id == DefaultAuthor.Id && n.Catalog.Id == catId, false, resourceCollectionParameters); } return(notes); } }