Exemplo n.º 1
0
        public IPagedResults <CategoriesResponse> GetCategories(CategoriesRequest request)
        {
            var respone = new PagedResults <CategoriesResponse>();
            var query   = _categoriesRepository.GetAllNoneDeleted();

            respone.Total = query.Count();
            //sort  data
            if (!string.IsNullOrEmpty(request?.SortField))
            {
                OrderBy(ref query, request);
            }
            else
            {
                query = query.OrderBy(x => x.Name);
            }
            //pagging data
            if (request?.Skip != null && request.Take.HasValue)
            {
                Paging(ref query, request);
            }
            var result = Mapper.Map <List <Categories>, List <CategoriesResponse> >(query.ToList());

            respone.Data = result;
            return(respone);
        }
        /// <summary>
        /// Make a call to /v1/categories
        /// </summary>
        /// <returns>A Category Request to query against</returns>
        public ICategoryRequest GetCategories()
        {
            var req = new CategoriesRequest(_Settings);

            WireBeforeRequestEvents(req);
            WireAfterRequestEvents(req);
            return(req);
        }
        public async Task <IActionResult> Update([FromForm] CategoriesRequest request, int categoriesId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var result = await _categoriesServies.Update(request, categoriesId);

            return(Ok(result));
        }
Exemplo n.º 4
0
 public HttpResponseMessage GetAllCategories(CategoriesRequest request)
 {
     try
     {
         var users = _adminServices.GetCategories(request);
         return(users != null?Request.CreateResponse(HttpStatusCode.OK, users) :
                    Request.CreateResponse(HttpStatusCode.NoContent, Constants.ErrorMessageCodes.NoRecordsFoundMessage));
     }
     catch (Exception exception)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exception.Message));
     }
 }
Exemplo n.º 5
0
        public async Task <ApiResult <bool> > Update(CategoriesRequest request, int categoriesId)
        {
            var postcategories = await _context.Postcategories.FindAsync(categoriesId);

            if (postcategories == null)
            {
                return(new ApiResultErrors <bool>("Not found"));
            }
            postcategories.CategoryName        = request.CategoryName;
            postcategories.CategoryDescription = request.CategoryDescription;

            await _context.SaveChangesAsync();

            return(new ApiResultSuccess <bool>());
        }
Exemplo n.º 6
0
        public async Task <ApiResult <string> > Create(CategoriesRequest request)
        {
            var postcategories = new Postcategories()
            {
                CategoryName        = request.CategoryName,
                CategoryDescription = request.CategoryDescription
            };

            _context.Postcategories.Add(postcategories);
            var numRowChange = await _context.SaveChangesAsync();

            if (numRowChange > 0)
            {
                return(new ApiResultSuccess <string>("inserted"));
            }
            else
            {
                return(new ApiResultErrors <string>("Faild"));
            }
        }
        public object Get(CategoriesRequest request)
        {
            var cache = Redis.As<CategoryDto>();

            bool cacheExists = cache.Lists["categories"].Any();

            if (cacheExists)
            {
                var response = cache.Lists["categories"].AsEnumerable();
                return response.ToList<CategoryDto>();
            }

            var categoryList = MongoHost.Db.GetCollection<MongoCategory>("Categories").AsQueryable();

            var categoryResponse = AutoMapper.Mapper.Map<List<CategoryDto>>(categoryList.ToList());

            cache.Lists["categories"].Clear();
            cache.Lists["categories"].AddRange(categoryResponse);

            return categoryResponse;
        }
Exemplo n.º 8
0
 public CategoriesResponse Get(CategoriesRequest req)
 {
     return(Exec(req, r => r.CategoriesResponse));
 }
        public void CategoriesRequest()
        {
            CategoriesRequest categoriesRequest = new CategoriesRequest();

            var response = session.Get(categoriesRequest);
        }
Exemplo n.º 10
0
        public CategoriesResponse GetCategories(CategoriesRequest categoriesRequest)
        {
            string baseUrl = string.Concat(m_referenceEndpoint, "/categories");

            return RequestUtility.ExecuteGetRequest<CategoriesResponse, CategoriesRequest>(baseUrl, m_authToken, categoriesRequest);
        }
Exemplo n.º 11
0
        public IActionResult CategoriesPost([FromHeader] string secret, [FromHeader] string token, [FromBody] CategoriesRequest categoriesRequest)
        {
            string exampleJson = null;

            var example = exampleJson != null
            ? JsonConvert.DeserializeObject <List <Category> >(exampleJson)
            : default(List <Category>);

            return(new ObjectResult(example));
        }