/// <summary> /// Adds the one asyncrounously. /// </summary> /// <typeparam name="TEntity">The type of the entity.</typeparam> /// <param name="item">The item.</param> /// <returns></returns> public async Task <IGetSingleResult <TEntity> > AddOneAsync <TEntity>(TEntity item) where TEntity : class, new() { var res = new GetSingleResult <TEntity>(); try { var collection = GetCollection <TEntity>(); await collection.InsertOneAsync(item); res.Success = true; res.Message = "OK"; return(res); } catch (Exception ex) { res.Message = NotificationHelper.NotifyException("AddOne", "Exception adding one " + typeof(TEntity).Name, ex); return(res); } }
public GetSingleResult Execute(GetOne search) { var book = context.Books.AsQueryable(); var reponse = new GetSingleResult { Item = book.Select(x => new BookDto { Id = x.Id, Title = x.Title, Price = x.BookPublishers.Select(bp => bp.Price).FirstOrDefault(), CategoryName = x.Category.Name, Publishers = x.BookPublishers.Select(bp => bp.Publisher.Name), AuthorsNames = x.BookAuthors.Select(ba => ba.Author.FirstName), Src = x.Image.Src, Alt = x.Image.Alt }).Where(b => b.Id == search.Id).FirstOrDefault() }; return(reponse); }
/// <summary> /// Gets the one asynchronously. /// </summary> /// <typeparam name="TEntity">The type of the entity.</typeparam> /// <param name="filter">The filter.</param> /// <returns></returns> public async Task <IGetSingleResult <TEntity> > GetOneAsync <TEntity>(FilterDefinition <TEntity> filter) where TEntity : class, new() { var response = new GetSingleResult <TEntity>(); try { var collection = GetCollection <TEntity>(); var entity = await collection.Find(filter).SingleOrDefaultAsync(); if (entity == null == false) { response.Entity = entity; } response.Success = true; return(response); } catch (Exception ex) { response.Message = NotificationHelper.NotifyException("GetOne", "Exception getting one " + typeof(TEntity).Name, ex); return(response); } }