Esempio n. 1
0
        public async Task <Result> CreateSettingsForUser(string access_token, SettingsDto settings)
        {
            (var userId, var result) = await _token_validator.ValidateAsync(_client, access_token);

            try
            {
                if (result.Succeeded)
                {
                    if (settings.Device == null)
                    {
                        settings.Device = "undefined";
                    }

                    //var unixtime = (uint)(DateTime.UtcNow - DateTime.UnixEpoch).TotalSeconds;
                    //if (Math.Abs(unixtime - settings.SyncTime) > 100)
                    //    settings.SyncTime = unixtime;

                    var userSettings = await _store.SettingsStore.FindByUserId(userId);

                    settings.GibbonAccountId = userId;
                    if (userSettings == null)
                    {
                        var settingsModel = settings.ToModel();
                        await _store.SettingsStore.CreateAsync(settingsModel);
                    }
                    else
                    {
                        userSettings.GroupName         = settings.GroupName;
                        userSettings.GroupLink         = settings.GroupLink;
                        userSettings.AccentColor       = settings.AccentColor;
                        userSettings.CustomAccentColor = settings.CustomAccentColor;
                        userSettings.BackDrop          = settings.BackDrop;
                        userSettings.ThemeState        = settings.ThemeState;
                        userSettings.LastSyncUnixTime  = settings.SyncTime;
                        userSettings.Device            = settings.Device;
                        await _store.UpdateAsync(userSettings);
                    }
                    await _store.SaveChangesAsync();
                }
                return(result);
            }
            catch (SqlException)
            {
                var error = new Error(ErrorCodes.DataBaseError);
                return(Result.Failed(error));
            }
            catch (ArgumentException)
            {
                var error = new Error(ErrorCodes.InvalidParam);
                return(Result.Failed(error));
            }
            catch
            {
                var error = new Error(ErrorCodes.UndefinedError);
                return(Result.Failed(error));
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (string.IsNullOrEmpty(DownloadToken))
            {
                return(Page());
            }

            if (id == null)
            {
                return(NotFound());
            }

            Paper = await _context.Papers.Include(paper => paper.Author).FirstOrDefaultAsync(m => m.ID == id);

            if (Paper == null)
            {
                return(NotFound());
            }

            var result = await _tokenValidator.ValidateAsync(Paper, DownloadToken);

            if (result.Succeeded)
            {
                try
                {
                    var pdfFile = await _pdfBuilder.GetPdfAsync(Paper);

                    return(pdfFile);
                }
                catch (FileNotFoundException)
                {
                    return(NotFound());
                }
            }
            else
            {
                StatusMessage = $"Error: {result.Error}";
                return(Page());
            }
        }