public static CustomerProduct ConvertCustomerProductDTOToCustomerProduct(this CustomerProductDTO customerProductDTO) { CustomerProduct customerProduct = new CustomerProduct(); customerProduct.Customer.Id = customerProductDTO.CustomerId; customerProduct.Product.Id = customerProductDTO.ProductId; // caso seja preciso, pode ser passado o database por parâmetro e preeencher // os outros dados, no momento, não foi preciso return(customerProduct); }
public IActionResult Update([FromBody] CustomerProductDTO customerProductDTO) { if (customerProductDTO == null) { return(NotFound()); } CustomerProduct customerProduct = customerProductDTO.ConvertCustomerProductDTOToCustomerProduct(); return(Execute(() => _baseCustomerProductService.Update(customerProduct))); }
public ActionResult Post([FromBody] CustomerProductDTO value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (value == null) { return(BadRequest()); } repoWrapper.CustomerProduct.Insert(mapper.Map <CustomerProduct>(value)); repoWrapper.Save(); return(Ok()); }
public ActionResult Put(Guid id, [FromBody] CustomerProductDTO value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != value.Id) { return(BadRequest("Doesnt exist.")); } var customerProduct = repoWrapper.CustomerProduct.GetById(id); if (customerProduct == null) { return(BadRequest()); } mapper.Map <CustomerProductDTO, CustomerProduct>(value, customerProduct); repoWrapper.Save(); return(Ok()); }
public IActionResult Create([FromBody] CustomerProductDTO customerProductDTO) { if (customerProductDTO is null) { throw new ArgumentNullException(nameof(customerProductDTO)); } if (customerProductDTO is null) { throw new ArgumentNullException(nameof(customerProductDTO)); } if (customerProductDTO == null) { return(NotFound()); } CustomerProduct customerProduct = customerProductDTO.ConvertCustomerProductDTOToCustomerProduct(); return(Execute(() => _baseCustomerProductService.Add <CustomerProduct>(customerProduct).Id)); }