Esempio n. 1
0
        public async Task TryInsert(Cause Cause, Action <Cause, string> onSuccess, Action <Exception, string> onFail, CascadingAppStateProvider state)
        {
            try
            {
                string status = "";
                if (await _onlineState.IsOnline())
                {
                    CauseRequestInsert  req = new() { Cause = Cause };
                    CauseResponseInsert ret = await _causeService.InsertAsync(req);

                    if (ret.Success)
                    {
                        Cause  = ret.Cause;
                        status = ret.Status;
                        if (state.AppState.UseIndexedDB)
                        {
                            await _indexedDBManager.OpenDb();

                            await _indexedDBManager.ClearStore("Blobs");
                        }
                    }
                    else
                    {
                        throw new Exception(ret.Status);
                    }
                }
                else
                {
                    throw new Exception(RequestCodes.FIVE_ZERO_FOUR);
                }

                onSuccess(Cause, status);
            }
            catch (Exception e)
            {
                onFail(e, RequestCodes.FIVE_ZERO_ZERO);
            }
        }
Esempio n. 2
0
        public override async Task <CauseResponseInsert> Insert(CauseRequestInsert request, ServerCallContext context)
        {
            var response = new CauseResponseInsert();

            try
            {
                Cause cacheEntry = await _manager.Insert(request.Cause);

                Cache.Remove(_cache, "Cause.");
                var result = (await _manager.Get(x => x.Id == cacheEntry.Id)).FirstOrDefault();
                if (result != null)
                {
                    string cacheKey          = "Cause.GetById::" + cacheEntry.Id.ToString();
                    var    cacheEntryOptions = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(_cacheTimeInSeconds));
                    _cache.Set(cacheKey, cacheEntry, cacheEntryOptions);
                    response.Cause   = cacheEntry;
                    response.Success = true;
                    response.Status  = RequestCodes.TWO_ZERO_ZERO + ", inserted 1 row and then selected 1 row from " + Cache.Database;
                    response.Error   = "";
                }
                else
                {
                    response.Success = false;
                    response.Status  = RequestCodes.FIVE_ZERO_ONE;
                    response.Error   = "Could not find setting after adding it.";
                }
            }
            catch (Exception e)
            {
                response.Success = false;
                response.Status  = RequestCodes.FIVE_ZERO_ZERO;
                response.Error   = e.ToString();
            }

            return(await Task.FromResult <CauseResponseInsert>(response));
        }