public virtual ActionResult Create(ProductTypeModel model) { _ProductTypeService.AddProductType(model); var sd = _uow.SaveChanges(); return(null); }
public async Task <IActionResult> AddProductType([FromBody] ProductTypeViewModel formdata) { try { if (formdata == null) { return(BadRequest(new JsonResult(new { message = "object sent from client is null." }))); } else if (!ModelState.IsValid) { return(BadRequest("Invalid model object sent from client.")); } var productType = _mapper.Map <ProductTypeDto>(formdata); var productTypeData = await _productTypeService.AddProductType(productType); if (productTypeData == -1) { return(NotFound()); } productType.Id = productTypeData; var addedTestresult = _mapper.Map <ProductTypeViewModel>(productType); return(CreatedAtAction(nameof(GetProductType), new { id = productTypeData }, addedTestresult)); } catch (Exception e) { return(StatusCode(500, $"Something went wrong inside add testresult action: {e.Message}")); } }
public ProductType Post([FromBody] ProductType productType) { bool validId = Guid.TryParse(User.FindFirst("sub")?.Value, out Guid storeId); if (!validId) { throw new Exception("Invalid user id"); } var result = _productTypeService.AddProductType(storeId, productType); return(result); }