示例#1
0
        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());
        }
示例#2
0
        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"));
            }
        }
示例#3
0
        public async void CanCheckIfDeliveryExistsByDeliveryId()
        {
            var exists = await deliveryService.DeliveryExists(1);

            Assert.True(exists);
        }