public List <CurrencyModel> ReadCurrencyFromDB() { try { Mapper.Initialize(cfg => { cfg.CreateMap <ExchangeRate, CurrencyModel>(); }); List <CurrencyModel> currencyModelList = new List <CurrencyModel>(); using (CurrancyEntities entities = new CurrancyEntities()) { 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); } catch (Exception EX) { return(null); } }
public CurrencyModel 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); // 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 currencyModel; //} // return currencyModel; ExchangeRate exchangeRate; using (CurrancyEntities entities = new CurrancyEntities()) { exchangeRate = (from c in entities.ExchangeRates where c.ID == currencyModel.ID select c).FirstOrDefault(); } exchangeRate = exchangeRate = Mapper.Map <CurrencyModel, ExchangeRate>(currencyModel); using (CurrancyEntities entities = new CurrancyEntities()) { entities.Configuration.ValidateOnSaveEnabled = false; entities.Entry(exchangeRate).State = System.Data.Entity.EntityState.Modified; entities.SaveChanges(); entities.Configuration.ValidateOnSaveEnabled = true; int result = entities.SaveChanges(); if (result == 1) { return(currencyModel); } } return(currencyModel); }
public CurrencyModel ReadCurrencyFromDB(int ID) { //Mapper.Initialize(cfg => //{ // cfg.CreateMap<ExchangeRate, CurrencyModel>(); //}); CurrencyModel model = new CurrencyModel(); using (CurrancyEntities entities = new CurrancyEntities()) { var currency = (from customer in entities.ExchangeRates.Where(p => p.ID == ID) select customer).SingleOrDefault(); model = Mapper.Map <ExchangeRate, CurrencyModel>(currency); } return(model); }
public ExchangeRate SaveCurrency(CurrencyModel currencyModel) { //Mapper.Initialize(cfg => //{ // cfg.CreateMap<CurrencyModel,ExchangeRate>(); //}); ExchangeRate newRate = new ExchangeRate(); using (CurrancyEntities entities = new CurrancyEntities()) { newRate = Mapper.Map <CurrencyModel, ExchangeRate>(currencyModel); entities.ExchangeRates.Add(newRate); int result = entities.SaveChanges(); if (result == 1) { return(newRate); } } return(newRate); }
public bool DeleteCurrency(CurrencyModel currencyModel) { //Mapper.Initialize(cfg => //{ // cfg.CreateMap<CurrencyModel, ExchangeRate>(); //}); using (CurrancyEntities entities = new CurrancyEntities()) { 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); } }