Ejemplo n.º 1
0
        public T UpdateTable <T>(bool isConnected, T t, HttpRequestMethods method, string route = "", int?id = null) where T : class
        {
            T retVal = default(T);

            if (isConnected)
            {
                try
                {
                    var x = UpdateOfflineDb(t, method, route, id);

                    (t as District).PK_District = 0;
                    var jsonString = JsonConvert.SerializeObject(t);
                    var result     = edr.ExecuteRequest(route, method, jsonString, id);
                    if (method.ToString() != "Put")
                    {
                        retVal = JsonConvert.DeserializeObject <T>(result.ToString());
                    }
                }
                catch (Exception e)
                {
                }

                return(retVal);
            }
            else
            {
                // we're offline - add transaction to sync
                _ss.AddTransactionToSyncTable(new Sync {
                    Active = true, Entity = JsonConvert.SerializeObject(t), EntityType = route.Replace("api/", "").Replace("/", ""), Method = method, Id = id
                });;
                return(UpdateOfflineDb(t, method, route, id));
            }
        }