Exemple #1
0
 public void UpdateUpload(AppDataUpload data)
 {
     connection.Update(data);
 }
Exemple #2
0
 public void AddUpload(AppDataUpload data)
 {
     connection.InsertOrReplace(data);
 }
Exemple #3
0
 public void DeleteUpload(AppDataUpload data)
 {
     connection.Delete <AppDataUpload>(data.ItemId);
 }
Exemple #4
0
        public static async Task <AppDataUpload> PrepCreationForUpload(FeedItem created, bool updatingRemote)
        {
            created.AppVersionNumber = Helpers.AppVersionNumber;

            AppDataUpload uploadData = new AppDataUpload
            {
                ItemId      = created.Id,
                Name        = created.Name,
                CreatedAt   = created.CreatedAt,
                Description = created.Description,
                ImageUrl    = created.ImageUrl,
                JsonData    = JsonConvert.SerializeObject(created,
                                                          new JsonSerializerSettings
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
                    MaxDepth = 5
                }),
                FilesJson = JsonConvert.SerializeObject(GetFilesForCreation(created))
            };

            DatabaseManager databaseManager = await GetDatabaseManager();

            // Remove from cache when added to upload queue
            if (created is LearningActivity createdActivity)
            {
                uploadData.UploadType  = (updatingRemote) ? UploadType.UpdatedActivity : UploadType.NewActivity;
                uploadData.UploadRoute = (updatingRemote) ? "api/learningactivities?id=" + created.Id : "api/learningactivities";

                string cacheJson = databaseManager.CurrentUser.LocalCreatedActivitiesJson;
                List <LearningActivity> inProgress = (string.IsNullOrWhiteSpace(cacheJson)) ?
                                                     new List <LearningActivity>() :
                                                     JsonConvert.DeserializeObject <List <LearningActivity> >(cacheJson);

                int existingInd = inProgress.FindIndex((la) => la.Id == created.Id);
                if (existingInd != -1)
                {
                    inProgress.RemoveAt(existingInd);
                }

                databaseManager.CurrentUser.LocalCreatedActivitiesJson = JsonConvert.SerializeObject(inProgress);
            }
            else if (created is ActivityCollection createdCollection)
            {
                uploadData.UploadType  = (updatingRemote) ? UploadType.UpdatedCollection : UploadType.NewCollection;
                uploadData.UploadRoute = (updatingRemote) ? "api/activitycollections?id=" + created.Id : "api/activitycollections";

                string cacheJson = databaseManager.CurrentUser.LocalCreatedCollectionsJson;
                List <ActivityCollection> inProgress = (string.IsNullOrWhiteSpace(cacheJson)) ?
                                                       new List <ActivityCollection>() :
                                                       JsonConvert.DeserializeObject <List <ActivityCollection> >(cacheJson);

                int existingInd = inProgress.FindIndex((la) => la.Id == created.Id);
                if (existingInd != -1)
                {
                    inProgress.RemoveAt(existingInd);
                }

                databaseManager.CurrentUser.LocalCreatedCollectionsJson = JsonConvert.SerializeObject(inProgress);
            }

            databaseManager.AddUpload(uploadData);
            databaseManager.AddUser(databaseManager.CurrentUser);

            return(uploadData);
        }