public void UpdateContractById(int contractId, ContractUpdateModel contractToUpdate)
        {
            var entity = _ctx.Contracts.Single(e => e.ContractId == contractId);

            if (entity != null)
            {
                if (contractToUpdate.ContractDescription != null)
                {
                    entity.ContractDescription = contractToUpdate.ContractDescription;
                }
                if (contractToUpdate.CharacterId != null)
                {
                    entity.CharacterId = (int)contractToUpdate.CharacterId;
                }
                if (contractToUpdate.PlanetId != null)
                {
                    entity.PlanetId = (int)contractToUpdate.PlanetId;
                }
                if (contractToUpdate.ShipId != null)
                {
                    entity.ShipId = (int)contractToUpdate.ShipId;
                }
                if (contractToUpdate.WeaponId != null)
                {
                    entity.ShipId = (int)contractToUpdate.WeaponId;
                }
                if (contractToUpdate.ContractStatus != null)
                {
                    entity.ContractStatus = (ContractStatus)contractToUpdate.ContractStatus;
                }
                entity.ContractPrice = entity.Character.Price + entity.Planet.Price + entity.Ship.ShipPrice + entity.Weapon.Price;
                _ctx.SaveChanges();
            }
        }
Beispiel #2
0
        public IHttpActionResult UpdateContract([FromUri] int contractId, ContractUpdateModel contractToUpdate)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateContractService();

            service.UpdateContractById(contractId, contractToUpdate);
            return(Ok());
        }