Exemplo n.º 1
0
        private CountryModel2 Load(dynamic d)
        {
            if (d == null)
            {
                return(null);
            }
            CountryModel2 country = JsonConvert.DeserializeObject <CountryModel2>(Convert.ToString(d.INFO));

            country.Id = d.ID;
            return(country);
        }
Exemplo n.º 2
0
 public new async Task <IEnumerable <CountryModel2> > GetAll() => await Task.Run(() => {
     List <CountryModel2> list = new List <CountryModel2>();
     string sql = "SELECT c.ID, c.INFO FROM Country c";
     IEnumerable <dynamic> coutries = BLL.Cnn(cfg).Query(sql);
     foreach (dynamic d in coutries)
     {
         CountryModel2 country = JsonConvert.DeserializeObject <CountryModel2>(Convert.ToString(d.INFO));
         country.Id            = d.ID;
         list.Add(country);
     }
     return(list);
 });
Exemplo n.º 3
0
        public async Task <bool> Save(CountryModel2 model) => await Task.Run(() => {
            if (!IsValid(model.Id))
            {
                return(false);
            }
            if (model.Address == null)
            {
                return(false);
            }
            string info = JsonConvert.SerializeObject(model);
            string sql  = "SELECT COUNT(*) FROM Country WHERE Id = :id";
            bool exists = BLL.Cnn(cfg).ExecScalar <long>(sql, new { id = model.Id }) == 1;
            if (exists)
            {
                BLL.Cnn(cfg).UpdateSQL(nameof(Country), new { model.Id, info }, "Id");
            }
            else
            {
                BLL.Cnn(cfg).InsertSQL(nameof(Country), new { model.Id, info });
            }

            return(true);
        });