internal static CategoryViewModel MapCategoryReqNineDTOToCategoryViewModel(CategoryReqNineDTO dto, string url = "")
 {
     if (dto == null || dto.CategoryId <= 0 || string.IsNullOrEmpty(dto.CategoryName))
     {
         return(null);
     }
     return(new CategoryViewModel
     {
         Url = url,
         Id = dto.CategoryId,
         Name = dto.CategoryName,
         Description = dto.CategoryDescription
     });
 }
        public IActionResult GetCategory(int id)
        {
            CategoryReqNineDTO c = _unitOfWork.Categories.GetCategoryAsDTO(id);

            if (c == null || c.CategoryId <= 0)
            {
                return(NotFound());
            }
            CategoryViewModel vm = CategoryMapper.MapCategoryReqNineDTOToCategoryViewModel(c, Url.Link(nameof(GetCategory), new { id }));

            if (vm == null)
            {
                return(NotFound());
            }
            return(Ok(vm));
        }
        public IActionResult CreateCategory([FromBody] CategoryCreateViewModel vmodel)
        {
            if (vmodel == null)
            {
                return(null);
            }
            CategoryReqNineDTO c = _unitOfWork.Categories.Create(vmodel.Name, vmodel.Description);

            if (c == null || c.CategoryId <= 0)
            {
                return(null);
            }
            _unitOfWork.Complete();
            CategoryViewModel vm = CategoryMapper.MapCategoryReqNineDTOToCategoryViewModel(c, Url.Link(nameof(GetCategory), new { c.CategoryId }));

            if (vm == null)
            {
                return(null);                                                               /////
            }
            return(Created(Url.RouteUrl(nameof(CreateCategory)) + "/" + c.CategoryId, vm)); // StatusCode(201);   //Ok(vm);
        }