コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        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);
        }