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 CurrencyModel ReadCurrencyFromDB(int ID) { Mapper.Initialize(cfg => { cfg.CreateMap <ExchangeRate, CurrencyModel>(); }); CurrencyModel model = new CurrencyModel(); using (AirLineEntities entities = new AirLineEntities()) { var currency = (from customer in entities.ExchangeRates.Where(p => p.ID == ID) select customer).SingleOrDefault(); model = Mapper.Map <ExchangeRate, CurrencyModel>(currency); } return(model); }
public bool SaveCurrency(CurrencyModel currencyModel) { Mapper.Initialize(cfg => { cfg.CreateMap <CurrencyModel, ExchangeRate>(); }); using (AirLineEntities entities = new AirLineEntities()) { ExchangeRate newRate = new ExchangeRate(); newRate = Mapper.Map <CurrencyModel, ExchangeRate>(currencyModel); entities.ExchangeRates.Add(newRate); 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); } }
public List <CurrencyModel> ReadCurrencyFromDB() { Mapper.Initialize(cfg => { cfg.CreateMap <ExchangeRate, CurrencyModel>(); }); List <CurrencyModel> currencyModelList = new List <CurrencyModel>(); using (AirLineEntities entities = new AirLineEntities()) { var currencyList = (from customer in entities.ExchangeRates select customer).ToList(); foreach (var item in currencyList) { CurrencyModel model = Mapper.Map <ExchangeRate, CurrencyModel>(item); currencyModelList.Add(model); } } return(currencyModelList); }