Пример #1
0
        public async Task SaveTodoItemAsync(BelProduct product, bool isNewItem = false)
        {
            // RestUrl = http://developer.xamarin.com:8081/api/todoitems
            var uri = new Uri(string.Format(Constants.BackendUrl, string.Empty));

            try {
                var json    = JsonConvert.SerializeObject(product);
                var content = new StringContent(json, Encoding.UTF8, "application/json");

                HttpResponseMessage response = null;
                if (isNewItem)
                {
                    response = await client.PostAsync(uri, content);
                }
                else
                {
                    response = await client.PutAsync(uri, content);
                }

                if (response.IsSuccessStatusCode)
                {
                    Debug.WriteLine(@"				TodoItem successfully saved.");
                }
            } catch (Exception ex) {
                Debug.WriteLine(@"				ERROR {0}", ex.Message);
            }
        }
Пример #2
0
        private static ObservableCollection <BelProduct> TransformObject(List <BelProduct> products)
        {
            //throw new NotImplementedException();

            ObservableCollection <BelProduct> obj = new ObservableCollection <BelProduct>();

            //List<BelProduct> _list = new List<BelProduct>();
            //foreach (var item in products)
            //{
            //    _list.Add(item);
            //}
            //string asciichar = (Convert.ToChar(62)).ToString();
            foreach (var p in products)
            {
                BelProduct _bp = new BelProduct();
                _bp.SeriesId    = p.SeriesId;
                _bp.TypeId      = p.TypeId;
                _bp.ProductName = p.ProductName;
                //_bp.ShortDesc = Regex.Replace(p.ShortDesc, @"<(.|\n)*?>");
                _bp.ShortDesc   = Regex.Replace(p.ShortDesc, @"<(.|\n)*?>", string.Empty);
                _bp.LongDesc    = p.LongDesc;
                _bp.FilePath    = p.FilePath;
                _bp.Formulation = p.Formulation;
                //_bp.ProductInfo = Regex.Replace(p.LongDesc.Substring(0, 100), @"<(.|\n)*?>", string.Empty) + "...";
                _bp.ProductImage = "belzonalogo_en_full.png";
                //_bp.NextImage = (Convert.ToChar(62)).ToString();
                obj.Add(_bp);
            }
            return(obj);
        }
Пример #3
0
 public int SaveItem(BelProduct item)
 {
     lock (locker) {
         if (item.SeriesId != 0)
         {
             database.Update(item);
             return(item.SeriesId);
         }
         else
         {
             return(database.Insert(item));
         }
     }
 }