예제 #1
0
        public ActionResult Index()
        {
            var listProductDto        = productServiceClient.findAll();
            List <ProductModel> model = listProductDto.Select(productDto => MVCModelToDTOUtil.ToProductModelMap(productDto)).ToList();

            return(View(model));
        }
예제 #2
0
        public IActionResult Get()
        {
            ProductDTO[]        listProductDto = productServiceClient.findAllAsync().GetAwaiter().GetResult();
            List <ProductModel> model          = listProductDto.Select(productDto => MVCModelToDTOUtil.ToProductModelMap(productDto)).ToList();

            return(Ok(model));
        }
예제 #3
0
        public JsonResult Create(ProductModel product)
        {
            var errors = new Dictionary <string, object>();

            try
            {
                if (ModelState.IsValid)
                {
                    ProductDTO productDTO = MVCModelToDTOUtil.ToProductDTOMap(product);
                    bool       result     = productServiceClient.create(productDTO);
                    if (!result)
                    {
                        errors.Add("service", "error");
                    }
                }
                else
                {
                    errors = GetErrorsFromModelState();
                }
            }
            catch (Exception e)
            {
                errors.Add("exception", e.Message);
            }
            return(Json(new
            {
                Valid = ModelState.IsValid,
                Errors = errors
            }));
        }
예제 #4
0
 public ActionResult Update(ProductModel product)
 {
     try
     {
         if (ModelState.IsValid)
         {
             ProductDTO productDTO = MVCModelToDTOUtil.ToProductDTOMap(product);
             bool       result     = productServiceClient.update(productDTO);
             if (result)
             {
                 return(RedirectToAction("Index"));
             }
             else
             {
                 //TODO: error
                 return(View());
             }
         }
         return(View(product));
     }
     catch (Exception e)
     {
         return(View());
     }
 }
예제 #5
0
        private IActionResult getProductModelById(int id)
        {
            ProductDTO productDto = productServiceClient.findByIdAsync(id).GetAwaiter().GetResult();

            if (productDto == null)
            {
                return(NotFound());
            }
            return(Ok(MVCModelToDTOUtil.ToProductModelMap(productDto)));
        }
예제 #6
0
        public IActionResult Put(int id, [FromForm] ProductModel product)
        {
            ProductDTO productDTO = MVCModelToDTOUtil.ToProductDTOMap(product);
            bool       result     = productServiceClient.updateAsync(productDTO).GetAwaiter().GetResult();

            if (!result)
            {
                return(BadRequest());
            }
            return(NoContent());
        }
예제 #7
0
        public IActionResult Post([FromForm] ProductModel product)
        {
            ProductDTO productDTO = MVCModelToDTOUtil.ToProductDTOMap(product);
            bool       result     = productServiceClient.createAsync(productDTO).GetAwaiter().GetResult();

            if (!result)
            {
                return(BadRequest());
            }
            return(CreatedAtRoute("GetProduct", new { id = product.Id }, product));
        }
예제 #8
0
        private ProductModel getProductModelById(int?id)
        {
            if (!id.HasValue)
            {
                return(null);
            }
            ProductDTO productDto = productServiceClient.findById(id.Value);

            if (productDto == null)
            {
                return(null);
            }
            return(MVCModelToDTOUtil.ToProductModelMap(productDto));
        }
예제 #9
0
        public IActionResult GetDataTable([FromQuery] jQueryDataTableParamModel param)
        {
            ContainerDTO <ProductDTO>          productContainerDto = productServiceClient.findAllPagedAsync(param.start, param.length).GetAwaiter().GetResult();
            List <ProductModel>                data = productContainerDto.list.Select(productDto => MVCModelToDTOUtil.ToProductModelMap(productDto)).ToList();
            jQueryDataTableData <ProductModel> dataTableResponse = new jQueryDataTableData <ProductModel>(param.draw, productContainerDto.total, data);

            return(Ok(dataTableResponse));
        }
예제 #10
0
        public JsonResult GetDataTable(jQueryDataTableParamModel param)
        {
            ContainerDTO <ProductDTO>          productContainerDto = productServiceClient.findAllPaged(param.start, param.length);
            List <ProductModel>                data = productContainerDto.list.Select(productDto => MVCModelToDTOUtil.ToProductModelMap(productDto)).ToList();
            jQueryDataTableData <ProductModel> dataTableResponse = new jQueryDataTableData <ProductModel>(param.draw, productContainerDto.total, data);

            return(Json(dataTableResponse, JsonRequestBehavior.AllowGet));
        }
예제 #11
0
        public JsonResult List()
        {
            ContainerDTO <ProductDTO> productContainerDto = productServiceClient.findAllPaged(0, 100); //TODO; implement paging
            List <ProductModel>       data = productContainerDto.list.Select(productDto => MVCModelToDTOUtil.ToProductModelMap(productDto)).ToList();

            return(Json(data, JsonRequestBehavior.AllowGet));
        }