コード例 #1
0
        public IActionResult UpdateOrder(string customerId, int id, [FromBody] OrdersForUpdateDTO order)
        {
            if (order == null)
            {
                return(BadRequest());//solictud erronea
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_customerRepository.CustomerExists(customerId))
            {
                return(NotFound());
            }

            var existingOrder = _customerRepository.GetOrder(customerId, id);

            if (existingOrder == null)
            {
                return(NotFound());
            }

            Mapper.Map(order, existingOrder);//El primer parametro es la nueva información y el segundo es el registro que teniamos anteriormente

            if (!_customerRepository.Save())
            {
                return(StatusCode(500, "Please verify your data"));
            }



            return(NoContent());
        }
コード例 #2
0
        public IActionResult UpdateOrder(string customerId, int id, [FromBody] OrdersForUpdateDTO order)
        {
            if (order == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (!_customerRepository.CustometExist(customerId))
            {
                return(NotFound());
            }

            var existingOrder = _customerRepository.GetOrder(customerId, id);

            if (existingOrder == null)
            {
                return(NotFound());
            }

            _mapper.Map(order, existingOrder);
            if (!_customerRepository.Save())
            {
                return(StatusCode(500, "Please verify your data"));
            }
            return(NoContent());
        }
コード例 #3
0
        public IActionResult UpdateOrder(int customerId, int id,
                                         [FromBody] OrdersForUpdateDTO order)
        {
            if (order == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var customer = Repository.Instance
                           .Customers.FirstOrDefault(c => c.Id == customerId);

            if (customer == null)
            {
                return(NotFound());
            }

            var orderFromRepository =
                customer.Orders.FirstOrDefault(o => o.OrderId == id);

            if (orderFromRepository == null)
            {
                return(NotFound());
            }
            orderFromRepository.CustomerId     = order.CustomerId;
            orderFromRepository.EmployeeId     = order.EmployeeId;
            orderFromRepository.OrderDate      = order.OrderDate;
            orderFromRepository.RequiredDate   = order.RequiredDate;
            orderFromRepository.ShippedDate    = order.ShippedDate;
            orderFromRepository.ShipVia        = order.ShipVia;
            orderFromRepository.Freight        = order.Freight;
            orderFromRepository.ShipName       = order.ShipName;
            orderFromRepository.ShipAddress    = order.ShipAddress;
            orderFromRepository.ShipCity       = order.ShipCity;
            orderFromRepository.ShipRegion     = order.ShipRegion;
            orderFromRepository.ShipPostalCode = order.ShipPostalCode;
            orderFromRepository.ShipCountry    = order.ShipCountry;

            return(NoContent());
        }
コード例 #4
0
        public IActionResult UpdateOrder(int customerId, int id,
                                         [FromBody] JsonPatchDocument <OrdersForUpdateDTO> patchDocument)
        {
            if (patchDocument == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            CustomerDTO customer = Repository.Instance.Customers.FirstOrDefault(c => c.Id == customerId);

            if (customer == null)
            {
                return(NotFound());
            }

            OrdersDTO orderFromRepository = customer.Orders.FirstOrDefault(o => o.OrderId == id);

            if (orderFromRepository == null)
            {
                return(NotFound());
            }

            var orderToUpdate = new OrdersForUpdateDTO()
            {
                CustomerId     = orderFromRepository.CustomerId,
                EmployeeId     = orderFromRepository.EmployeeId,
                OrderDate      = orderFromRepository.OrderDate,
                RequiredDate   = orderFromRepository.RequiredDate,
                ShippedDate    = orderFromRepository.ShippedDate,
                ShipVia        = orderFromRepository.ShipVia,
                Freight        = orderFromRepository.Freight,
                ShipName       = orderFromRepository.ShipName,
                ShipAddress    = orderFromRepository.ShipAddress,
                ShipCity       = orderFromRepository.ShipCity,
                ShipRegion     = orderFromRepository.ShipRegion,
                ShipPostalCode = orderFromRepository.ShipPostalCode,
                ShipCountry    = orderFromRepository.ShipCountry
            };

            patchDocument.ApplyTo(orderToUpdate, ModelState);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            orderFromRepository.CustomerId     = orderToUpdate.CustomerId;
            orderFromRepository.EmployeeId     = orderToUpdate.EmployeeId;
            orderFromRepository.OrderDate      = orderToUpdate.OrderDate;
            orderFromRepository.RequiredDate   = orderToUpdate.RequiredDate;
            orderFromRepository.ShippedDate    = orderToUpdate.ShippedDate;
            orderFromRepository.ShipVia        = orderToUpdate.ShipVia;
            orderFromRepository.Freight        = orderToUpdate.Freight;
            orderFromRepository.ShipName       = orderToUpdate.ShipName;
            orderFromRepository.ShipAddress    = orderToUpdate.ShipAddress;
            orderFromRepository.ShipCity       = orderToUpdate.ShipCity;
            orderFromRepository.ShipRegion     = orderToUpdate.ShipRegion;
            orderFromRepository.ShipPostalCode = orderToUpdate.ShipPostalCode;
            orderFromRepository.ShipCountry    = orderToUpdate.ShipCountry;

            return(NoContent());
        }