public async Task <IHttpActionResult> Put(int Id, Subjacent subjacent)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (Id != subjacent.Id)
            {
                return(BadRequest());
            }

            try
            {
                _db.UpdateGraph(subjacent, map => map
                                .AssociatedEntity(s => s.SubjacentType)
                                .AssociatedEntity(s => s.ContractType)
                                .AssociatedEntity(s => s.Book)
                                .OwnedCollection(s => s.UnderlyingTerms
                                                 //, with => with.OwnedEntity(u => u.Currency)
                                                 )
                                );
                await _db.SaveChangesAsync();
            }
            catch (DbEntityValidationException e)
            {
                List <string> errors = new List <string>();
                foreach (var eve in e.EntityValidationErrors)
                {
                    errors.Add(
                        string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State));
                    foreach (var ve in eve.ValidationErrors)
                    {
                        errors.Add(string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                                 ve.PropertyName, ve.ErrorMessage));
                    }
                }
                throw;
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!subjacentExist(Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp.Message);
                throw;
            }
            return(Updated(subjacent));
        }
        public async Task <IHttpActionResult> Put(int Id, LinkFxContractSignalContract fxContractSignalContract)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (Id != fxContractSignalContract.Id)
            {
                return(BadRequest());
            }

            try
            {
                _db.UpdateGraph(fxContractSignalContract, map => map
                                .AssociatedEntity(s => s.PurchaseContract)
                                .AssociatedEntity(s => s.SupplyContract)
                                .AssociatedEntity(s => s.FxContract)
                                );
                await _db.SaveChangesAsync();
            }
            catch (DbEntityValidationException e)
            {
                List <string> errors = new List <string>();
                foreach (var eve in e.EntityValidationErrors)
                {
                    errors.Add(
                        string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State));
                    foreach (var ve in eve.ValidationErrors)
                    {
                        errors.Add(string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                                 ve.PropertyName, ve.ErrorMessage));
                    }
                }
                throw;
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SignalContractExists(Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp.Message);
                throw;
            }
            return(Updated(fxContractSignalContract));
        }
        public async Task <IHttpActionResult> Put(int Id, [FromBody] TimeSerie timeSerie)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (Id != timeSerie.Id)
            {
                return(BadRequest());
            }

            try
            {
                _db.UpdateGraph(timeSerie, map => map
                                .AssociatedEntity(ts => ts.Currency)
                                .AssociatedEntity(ts => ts.Unit)
                                .OwnedCollection(ts => ts.Formulae, with => with.OwnedEntity(f => f.TimeSerie))
                                .OwnedCollection(ts => ts.CommodityHedges, with => with.OwnedEntity(ch => ch.TimeSerie))
                                .OwnedCollection(ts => ts.TimeSerieValues, with => with.OwnedEntity(tsv => tsv.TimeSerie))
                                );

                await _db.SaveChangesAsync();
            }
            catch (DbEntityValidationException e)
            {
                List <string> errors = new List <string>();
                foreach (var eve in e.EntityValidationErrors)
                {
                    errors.Add(string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                             eve.Entry.Entity.GetType().Name, eve.Entry.State));
                    foreach (var ve in eve.ValidationErrors)
                    {
                        errors.Add(string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                                 ve.PropertyName, ve.ErrorMessage));
                    }
                }
                throw;
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TimeSerieExists(Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(timeSerie));
        }
        public async Task <IHttpActionResult> Put(int Id, TimeSerieValue timeSerieValue)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (Id != timeSerieValue.Id)
            {
                return(BadRequest());
            }

            try
            {
                _db.UpdateGraph(timeSerieValue);
                await _db.SaveChangesAsync();
            }
            catch (DbEntityValidationException e)
            {
                List <string> errors = new List <string>();
                foreach (var eve in e.EntityValidationErrors)
                {
                    errors.Add(
                        string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State));
                    foreach (var ve in eve.ValidationErrors)
                    {
                        errors.Add(string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                                 ve.PropertyName, ve.ErrorMessage));
                    }
                }
                throw;
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!timeSerieValueExist(Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp.Message);
                throw;
            }
            return(Updated(timeSerieValue));
        }
        //[ValidateModelAttribute]
        public async Task <IHttpActionResult> PutHedge(int Id, [FromBody] FXHedge hedge) //
        {
            Configuration.Services.GetTraceWriter().Info(Request, "HedgeController", "");
            if (!ModelState.IsValid)
            {
                var errors = ModelState.Select(x => x.Value.Errors)
                             .Where(y => y.Count > 0)
                             .ToList();
                return(BadRequest(ModelState));
            }

            if (Id != hedge.Id)
            {
                return(BadRequest());
            }
            if (Id == 0)
            {
                hedge.CreationDate = DateTime.Now;
            }
            else
            {
                hedge.ModificationDate = DateTime.Now;
            }

            if (hedge.WorkflowStateId == 2)////en cours d’exécution
            {
                hedge.ExecutionDate = DateTime.Now;
            }

            try
            {
                // hedgeProvider.Update(hedge, Key);
                //_dbContext.Entry(entity).CurrentValues.SetValues(hedge);
                _dbContext.UpdateGraph(hedge, map => map
                                       .OwnedCollection(h => h.HedgeLegs, with => with.OwnedEntity(hleg => hleg.Operation, andWith => andWith.OwnedEntity(ope => ope.Cargo)))
                                       .OwnedCollection(h => h.ExecutionFXes)
                                       //.OwnedEntity(x => x.Address)
                                       //.AssociatedEntity(h=>h.HedgeType)
                                       );
                _dbContext.SaveChanges();
                //_ModelContext.GnlCoreModelContext.ExecuteStoreCommand("[compute]", new object[] { });
            }
            catch (DbEntityValidationException e)
            {
                List <string> errors = new List <string>();
                foreach (var eve in e.EntityValidationErrors)
                {
                    errors.Add(string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                             eve.Entry.Entity.GetType().Name, eve.Entry.State));
                    foreach (var ve in eve.ValidationErrors)
                    {
                        errors.Add(string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                                 ve.PropertyName, ve.ErrorMessage));
                    }
                }
                throw;
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HedgeExists(Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp.Message);
                throw;
            }
            return(Updated(hedge));
        }