Example #1
0
        public override async Task <PageList <GasLog> > GetEntitiesAsync(ResourceCollectionParameters resourceCollectionParameters = null)
        {
            try
            {
                var notes = await GetNotesAsync(new GasLog(), null, resourceCollectionParameters);

                if (notes == null)
                {
                    return(null);
                }
                var logList = notes.Select(note => NoteSerializer.GetEntity(note));
                var result  = new PageList <GasLog>(logList, notes.TotalCount, notes.CurrentPage, notes.PageSize);
                return(result);
            }
            catch (Exception e)
            {
                if (NoteSerializer.ProcessResult.Success)
                {
                    ProcessResult.WrapException(e);
                }
                else
                {
                    ProcessResult.PropagandaResult(NoteSerializer.ProcessResult);
                }

                return(null);
            }
        }
Example #2
0
        public override PageList <AutomobileInfo> GetEntities(ResourceCollectionParameters resourceCollectionParameters = null)
        {
            try
            {
                var notes = GetNotes(new AutomobileInfo(), null, resourceCollectionParameters);
                if (notes == null)
                {
                    return(null);
                }

                var carList = notes.Select(note => NoteSerializer.GetEntity(note));
                var result  = new PageList <AutomobileInfo>(carList, notes.TotalCount, notes.CurrentPage, notes.PageSize);
                return(result);
            }
            catch (Exception e)
            {
                if (NoteSerializer.ProcessResult.Success)
                {
                    ProcessResult.WrapException(e);
                }
                else
                {
                    ProcessResult.PropagandaResult(NoteSerializer.ProcessResult);
                }

                return(null);
            }
        }
Example #3
0
        public PageList <GasLog> GetGasLogs(int automobileId, ResourceCollectionParameters resourceCollectionParameters = null)
        {
            var subject = GasLog.GetNoteSubject(automobileId);
            var notes   = GetNotes(new GasLog(), n => n.Subject == subject, resourceCollectionParameters);
            var logList = notes.Select(note => NoteSerializer.GetEntity(note));
            var result  = new PageList <GasLog>(logList, notes.TotalCount, notes.CurrentPage, notes.PageSize);

            return(result);
        }
Example #4
0
        public async Task <IActionResult> Get([FromQuery] ResourceCollectionParameters resourceCollectionParameters)
        {
            var noteList = await _noteManager.GetNotesAsync(null, false, resourceCollectionParameters);

            if (!noteList.Any())
            {
                return(NotFound());
            }

            return(Ok(noteList));
        }
Example #5
0
        public async Task <IActionResult> Get([FromQuery] ResourceCollectionParameters resourceCollectionParameters)
        {
            var authors = await _authorManager.GetEntitiesAsync(null, resourceCollectionParameters);

            if (!authors.Any())
            {
                return(NotFound());
            }

            return(Ok(authors));
        }
Example #6
0
        public async Task <IActionResult> Get([FromQuery] ResourceCollectionParameters resourceCollectionParameters)
        {
            var renderLst = await _renderManager.GetEntitiesAsync(null, resourceCollectionParameters);

            if (!renderLst.Any())
            {
                return(NotFound());
            }

            return(Ok(renderLst));
        }
Example #7
0
        public async Task <IActionResult> GetMobiles([FromQuery] ResourceCollectionParameters resourceCollectionParameters)
        {
            var autos = await _automobileManager.GetEntitiesAsync(resourceCollectionParameters);

            if (!autos.Any())
            {
                return(NotFound());
            }

            return(Ok(autos));
        }
Example #8
0
        public async Task <ActionResult> Get([FromQuery] ResourceCollectionParameters resourceCollectionParameters)
        {
            var discounts = await _discountManager.GetEntitiesAsync(resourceCollectionParameters);

            if (!discounts.Any())
            {
                return(NotFound());
            }

            return(Ok(discounts));
        }
Example #9
0
        public async Task <IActionResult> Get([FromQuery] ResourceCollectionParameters resourceCollectionParameters)
        {
            var noteCatalogs = await _catalogManager.GetEntitiesAsync(null, resourceCollectionParameters);

            if (!noteCatalogs.Any())
            {
                return(NotFound());
            }

            return(Ok(noteCatalogs));
        }
Example #10
0
        public override PageList <GasLog> GetEntities(ResourceCollectionParameters resourceCollectionParameters = null)
        {
            var notes = GetNotes(new GasLog(), null, resourceCollectionParameters);

            if (notes == null)
            {
                return(null);
            }
            var logList = notes.Select(note => NoteSerializer.GetEntity(note));
            var result  = new PageList <GasLog>(logList, notes.TotalCount, notes.CurrentPage, notes.PageSize);

            return(result);
        }
Example #11
0
        public static (int pageIndex, int pageSize) GetPaginationTuple(this ResourceCollectionParameters parameter)
        {
            switch (parameter)
            {
            case null:
            {
                var defaultParam = new ResourceCollectionParameters();
                return(defaultParam.PageNumber, defaultParam.PageSize);
            }

            default:
                return(parameter.PageNumber, parameter.PageSize);
            }
        }
Example #12
0
 public IEnumerable <Appointment> GetAppointments(Expression <Func <Appointment, bool> > query, ResourceCollectionParameters resourceCollectionParameters = null)
 {
     return(_appointRepo.GetEntities().ToList());
 }
Example #13
0
        public async Task <PageList <HmmNote> > GetEntitiesAsync(Expression <Func <HmmNote, bool> > query = null, ResourceCollectionParameters resourceCollectionParameters = null)
        {
            var(pageIdx, pageSize) = resourceCollectionParameters.GetPaginationTuple();
            var notes = query == null
                ? DataContext.Notes.Include(n => n.Author).Include(n => n.Catalog)
                : DataContext.Notes.Include(n => n.Author).Include(n => n.Catalog).Where(query);

            var result = resourceCollectionParameters == null
                ? await PageList <HmmNote> .CreateAsync(notes, pageIdx, pageSize)
                : await PageList <HmmNote> .CreateAsync(notes.ApplySort(resourceCollectionParameters.OrderBy), pageIdx, pageSize);

            return(result);
        }
Example #14
0
 public abstract Task <PageList <T> > GetEntitiesAsync(ResourceCollectionParameters resourceCollectionParameters = null);
Example #15
0
 public abstract PageList <T> GetEntities(ResourceCollectionParameters resourceCollectionParameters = null);
Example #16
0
 public PageList <NoteRender> GetEntities(Expression <Func <NoteRender, bool> > query = null, ResourceCollectionParameters resourceCollectionParameters = null)
 {
     return(LookupRepo.GetEntities(query, resourceCollectionParameters));
 }
Example #17
0
        public async Task <PageList <NoteRender> > GetEntitiesAsync(Expression <Func <NoteRender, bool> > query = null, ResourceCollectionParameters resourceCollectionParameters = null)
        {
            var renders = await LookupRepo.GetEntitiesAsync(query, resourceCollectionParameters);

            return(renders);
        }
Example #18
0
        public async Task <PageList <NoteRender> > GetEntitiesAsync(Expression <Func <NoteRender, bool> > query = null, ResourceCollectionParameters resourceCollectionParameters = null)
        {
            try
            {
                var renders = await _dataSource.GetEntitiesAsync(query, resourceCollectionParameters);

                return(renders);
            }
            catch (Exception ex)
            {
                ProcessResult.WrapException(ex);
                return(null);
            }
        }
Example #19
0
        /// <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);
            }
        }
Example #20
0
 public PageList <NoteCatalog> GetEntities(Expression <Func <NoteCatalog, bool> > query = null, ResourceCollectionParameters resourceCollectionParameters = null)
 {
     try
     {
         var catalogs = _dataSource.GetEntities(query, resourceCollectionParameters);
         return(catalogs);
     }
     catch (Exception ex)
     {
         ProcessResult.WrapException(ex);
         return(null);
     }
 }
Example #21
0
        public async Task <PageList <Author> > GetEntitiesAsync(Expression <Func <Author, bool> > query = null, ResourceCollectionParameters resourceCollectionParameters = null)
        {
            try
            {
                var authors = await _authorRepo.GetEntitiesAsync(query, resourceCollectionParameters);

                return(authors);
            }
            catch (Exception ex)
            {
                ProcessResult.WrapException(ex);
                return(null);
            }
        }
Example #22
0
 public PageList <Subsystem> GetEntities(Expression <Func <Subsystem, bool> > query = null, ResourceCollectionParameters resourceCollectionParameters = null)
 {
     try
     {
         var sys = _dataSource.GetEntities(query, resourceCollectionParameters);
         return(sys);
     }
     catch (Exception ex)
     {
         ProcessResult.WrapException(ex);
         return(null);
     }
 }
Example #23
0
        public async Task <PageList <Author> > GetEntitiesAsync(Expression <Func <Author, bool> > query = null, ResourceCollectionParameters resourceCollectionParameters = null)
        {
            var authors = await _lookupRepo.GetEntitiesAsync(query, resourceCollectionParameters);

            return(authors);
        }
Example #24
0
        public async Task <PageList <Subsystem> > GetEntitiesAsync(Expression <Func <Subsystem, bool> > query = null, ResourceCollectionParameters resourceCollectionParameters = null)
        {
            var systems = await LookupRepo.GetEntitiesAsync(query, resourceCollectionParameters);

            return(systems);
        }
Example #25
0
        public static List <Link> CreatePaginationLinks <T>(this PageList <T> records, string routName, ActionContext context, LinkGenerator linkGen, ResourceCollectionParameters resourceCollectionParameters)
        {
            var links = new List <Link>();

            if (context == null || linkGen == null)
            {
                return(links);
            }

            var orderBy = resourceCollectionParameters != null ? resourceCollectionParameters.OrderBy : string.Empty;
            var fields  = resourceCollectionParameters != null ? resourceCollectionParameters.Fields : string.Empty;

            links.Add(new Link()
            {
                Title  = routName,
                Rel    = "self",
                Href   = linkGen.GetUriByRouteValues(context.HttpContext, routName, new { pageNumber = records.CurrentPage, records.PageSize, orderBy, fields }),
                Method = "Get"
            });

            if (records.HasPrevPage)
            {
                links.Add(new Link()
                {
                    Title  = routName,
                    Rel    = "prev_page",
                    Href   = linkGen.GetUriByRouteValues(context.HttpContext, routName, new { pageNumber = records.CurrentPage - 1, pageSize = records.PageSize, orderBy, fields }),
                    Method = "Get"
                });
            }

            if (records.HasNextPage)
            {
                links.Add(new Link()
                {
                    Title  = routName,
                    Rel    = "next_page",
                    Href   = linkGen.GetUriByRouteValues(context.HttpContext, routName, new { pageNumber = records.CurrentPage + 1, pageSize = records.PageSize, orderBy, fields }),
                    Method = "Get"
                });
            }

            return(links);
        }
Example #26
0
        public async Task <PageList <T> > GetEntitiesAsync <T>(Expression <Func <T, bool> > query = null, ResourceCollectionParameters resourceCollectionParameters = null)
        {
            var(pageIdx, pageSize) = resourceCollectionParameters.GetPaginationTuple();
            var entities = GetQueryableEntities <T>();

            var result = query == null
                ? await PageList <T> .CreateAsync(entities, pageIdx, pageSize)
                : await PageList <T> .CreateAsync(entities.Where(query), pageIdx, pageSize);

            return(result);
        }