public bool UpdateCurrency(CurrencyModel currencyModel) { Mapper.Initialize(cfg => { cfg.CreateMap <CurrencyModel, ExchangeRate>(); }); using (AirLineEntities entities = new AirLineEntities()) { ExchangeRate exchangeRate = (from c in entities.ExchangeRates where c.ID == currencyModel.ID select c).FirstOrDefault(); exchangeRate = Mapper.Map <CurrencyModel, ExchangeRate>(currencyModel); // int result = entities.SaveChanges(); // ExchangeRate exchangeRate = new ExchangeRate(); entities.Configuration.ValidateOnSaveEnabled = false; exchangeRate.ID = currencyModel.ID; entities.Entry(exchangeRate).State = System.Data.Entity.EntityState.Modified; entities.SaveChanges(); entities.Configuration.ValidateOnSaveEnabled = true; int result = entities.SaveChanges(); if (result == 1) { return(true); } } return(false); }
public bool DeleteCurrency(CurrencyModel currencyModel) { Mapper.Initialize(cfg => { cfg.CreateMap <CurrencyModel, ExchangeRate>(); }); using (AirLineEntities entities = new AirLineEntities()) { ExchangeRate exchangeRate = new ExchangeRate(); entities.Configuration.ValidateOnSaveEnabled = false; exchangeRate.ID = currencyModel.ID; entities.Entry(exchangeRate).State = System.Data.Entity.EntityState.Deleted; entities.SaveChanges(); entities.Configuration.ValidateOnSaveEnabled = true; int result = entities.SaveChanges(); return(true); } }