Exemplo n.º 1
0
        public IHttpActionResult UpdateShipById([FromUri] int shipId, ShipUpdateModel shipToUpdate)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateShipService();

            service.UpdateShipById(shipId, shipToUpdate);
            return(Ok());
        }
Exemplo n.º 2
0
        public void UpdateShipById(int shipId, ShipUpdateModel shipToUpdate)
        {
            var entity = _ctx.Ships.Single(e => e.ShipId == shipId);

            if (entity != null)
            {
                if (shipToUpdate.UpdatedShipName != null)
                {
                    entity.ShipName = shipToUpdate.UpdatedShipName;
                }
            }
            if (shipToUpdate.UpdatedShipClass != null)
            {
                entity.ShipClass = (ShipClass)shipToUpdate.UpdatedShipClass;
            }
            if (shipToUpdate.UpdatedShipModel != null)
            {
                entity.ShipModel = shipToUpdate.UpdatedShipModel;
            }
            if (shipToUpdate.UpdatedShipManufacturer != null)
            {
                entity.ShipManufacturer = shipToUpdate.UpdatedShipManufacturer;
            }
            if (shipToUpdate.UpdatedShipHyperdrive != null)
            {
                entity.ShipHyperdrive = (bool)shipToUpdate.UpdatedShipHyperdrive;
            }
            if (shipToUpdate.UpdatedShipLength != null)
            {
                entity.ShipLength = (int)shipToUpdate.UpdatedShipLength;
            }
            if (shipToUpdate.UpdatedShipMaxSpeed != null)
            {
                entity.ShipMaxSpeed = (int)shipToUpdate.UpdatedShipMaxSpeed;
            }
            if (shipToUpdate.UpdatedShipPrice != null)
            {
                entity.ShipPrice = (int)shipToUpdate.UpdatedShipPrice;
            }
            _ctx.SaveChanges();
        }