예제 #1
0
        /// <summary>
        /// The AddProducts.
        /// </summary>
        /// <param name="product">The product<see cref="Product"/>.</param>
        /// <returns>The <see cref="Task{bool}"/>.</returns>
        public async Task <bool> AddProducts(Product product)
        {
            var URI = AppConstants.AddProductUrl;

            try
            {
                var     current = Connectivity.NetworkAccess;
                Product result  = null;
                if (current != NetworkAccess.Internet || AppConstants.UseLocal)
                {
                    var locresult = await _productDBService.AddProducts(Mapper.Map <ProductDAO>(product));

                    return(locresult == 1);
                }
                else
                {
                    result = await _apiRepository.PostAsync <Product>(URI, product);
                }
                return(!(result == null));
            }
            catch (Exception)
            {
                // log exception
            }

            return(false);
        }
예제 #2
0
        /// <summary>
        /// The SyncToOffline.
        /// </summary>
        /// <param name="onlineProd">The onlineProd<see cref="List{Product}"/>.</param>
        /// <returns>The <see cref="Task"/>.</returns>
        private async Task SyncToOffline(List <Product> onlineProd)
        {
            var offTables = Mapper.Map <List <ProductDAO> >(onlineProd);

            foreach (var data in offTables)
            {
                var offentity = await _productDBService.GetProduct(data.Id);

                if (offentity != null)
                {
                    await _productDBService.Updateproduct(data);
                }
                else
                {
                    await _productDBService.AddProducts(data);
                }
            }
        }