public async Task <IActionResult> Update([FromBody] UpdateViewModel deliveryModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (deliveryModel.IdSale <= 0) { return(BadRequest()); } try { await _deliveryService.UpdateDelivery(deliveryModel); } catch (DbUpdateException) { // check out if exists if (!(await _deliveryService.DeliveryExists(deliveryModel.IdClient))) { return(NotFound()); } else { return(BadRequest()); } } return(Ok()); }
public async Task <IActionResult> Get(int id) { //if (!User.Identity.IsAuthenticated) //{ // return Unauthorized($"You are not authorized to get this resource"); //} if (await deliveryService.DeliveryExists(id)) { var delivery = await deliveryService.GetDeliveryById(id); return(Ok(MakeDeliveryViewModel(delivery))); } else { return(NotFound($"Delivery with id {id} was not found")); } }
public async void CanCheckIfDeliveryExistsByDeliveryId() { var exists = await deliveryService.DeliveryExists(1); Assert.True(exists); }