コード例 #1
0
        public void Update()
        {
            LoyaltyProgramContext db = new LoyaltyProgramContext();

            try {
                var country = db.Country.Where(x => x.CountryID == CountryID).FirstOrDefault();
                if (country == null)
                {
                    country               = new Country();
                    country.CreatedOn     = DateTime.Now;
                    country.IsDeactivated = false;
                    db.Country.Add(country);
                }
                country.Name       = Name;
                country.ModifiedOn = DateTime.Now;
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                db.Dispose();
            }
        }
コード例 #2
0
        public void Edit(int id)
        {
            LoyaltyProgramContext db = new LoyaltyProgramContext();

            try {
                var country = db.Country.Where(x => x.CountryID == id).FirstOrDefault();
                CountryID = country.CountryID;
                Name      = country.Name;
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                db.Dispose();
            }
        }
コード例 #3
0
        public void Delete(int id)
        {
            LoyaltyProgramContext db = new LoyaltyProgramContext();

            try
            {
                Country country = db.Country.Where(x => x.CountryID == id).FirstOrDefault();
                db.Country.Remove(country);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                db.Dispose();
            }
        }
コード例 #4
0
        public List <CountryListView> Search(string search)
        {
            LoyaltyProgramContext db = new LoyaltyProgramContext();

            try
            {
                CountryList = new List <CountryListView>();
                var countries = new List <Country>();
                if (search == null)
                {
                    countries = db.Country.ToList();
                }
                else
                {
                    countries = db.Country.Where(x => x.Name.Contains(search)).ToList();
                }
                foreach (var item in countries)
                {
                    CountryListView country = new CountryListView();
                    country.CountryID     = item.CountryID;
                    country.Name          = item.Name;
                    country.IsDeactivated = item.IsDeactivated;
                    country.CreatedOn     = item.CreatedOn;
                    country.ModifiedOn    = item.ModifiedOn;
                    CountryList.Add(country);
                }
                return(CountryList);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                db.Dispose();
            }
            return(null);
        }