public ActionResult Index() { var listProductDto = productServiceClient.findAll(); List <ProductModel> model = listProductDto.Select(productDto => MVCModelToDTOUtil.ToProductModelMap(productDto)).ToList(); return(View(model)); }
public IActionResult Get() { ProductDTO[] listProductDto = productServiceClient.findAllAsync().GetAwaiter().GetResult(); List <ProductModel> model = listProductDto.Select(productDto => MVCModelToDTOUtil.ToProductModelMap(productDto)).ToList(); return(Ok(model)); }
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 })); }
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()); } }
private IActionResult getProductModelById(int id) { ProductDTO productDto = productServiceClient.findByIdAsync(id).GetAwaiter().GetResult(); if (productDto == null) { return(NotFound()); } return(Ok(MVCModelToDTOUtil.ToProductModelMap(productDto))); }
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()); }
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)); }
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)); }
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)); }
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)); }
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)); }