Exemplo n.º 1
0
        public async Task <IActionResult> Browse()
        {
            var query = new BrowseRemarks();

            var remarks = await _remarkService.BrowseAsync(query);

            var categories = await _categorySevice.GetAsync();

            var result = remarks
                         .Select(x => new RemarkDto
            {
                Id           = x.Id,
                Name         = x.Name,
                Description  = x.Description,
                Latitude     = x.Latitude,
                Longitude    = x.Longitude,
                Author       = x.AuthorId,
                CategoryId   = x.CategoryId,
                CategoryName = categories.FirstOrDefault(y => y.Id == x.CategoryId)?.Name,
                Status       = x.Status.ToString()
            })
                         .ToList();

            return(Ok(result));
        }
        public RemarkModule(IRemarkService remarkService, IMapper mapper) : base(mapper, "remarks")
        {
            Get("", async args => await FetchCollection <BrowseRemarks, Remark>
                    (async x => await remarkService.BrowseAsync(x))
                .MapTo <RemarkDto>()
                .HandleAsync());

            Get("categories", async args => await FetchCollection <BrowseCategories, Category>
                    (async x => await remarkService.BrowseCategoriesAsync(x))
                .MapTo <RemarkCategoryDto>()
                .HandleAsync());

            Get("tags", async args => await FetchCollection <BrowseTags, Tag>
                    (async x => await remarkService.BrowseTagsAsync(x))
                .MapTo <TagDto>()
                .HandleAsync());

            Get("{id}", async args => await Fetch <GetRemark, Remark>
                    (async x => await remarkService.GetAsync(x.Id))
                .MapTo <RemarkDto>()
                .HandleAsync());
        }