Beispiel #1
0
        public bool CreateActivity(string personId, Activity activity, string appId)
        {
            string title = (activity.title ?? "").Trim();
            if (string.IsNullOrEmpty(title))
            {
                throw new Exception("Invalid activity: empty title");
            }
            string body = (activity.body ?? "").Trim();
            var time = UnixTime.ToInt64(DateTime.UtcNow);
            var act = new ActivityRow(personId, time.ToString())
                          {
                              person_id = personId,
                              app_id = appId,
                              title = title,
                              body = body,
                              created = time
                          };
            using (var db = new AzureRayaDataContext())
            {
                db.InsertOnSubmit(AzureRayaDataContext.TableNames.activities, act);
                db.SubmitChanges();

                var mediaItems = activity.mediaItems;
                if (mediaItems.Count != 0)
                {
                    foreach (var mediaItem in mediaItems)
                    {
                        var actm = new MediaItemRow(act.id, mediaItem.url)
                                       {
                                           activity_id = act.id,
                                           media_type = mediaItem.type.ToString().ToLower(),
                                           mime_type = mediaItem.mimeType,
                                           url = mediaItem.url
                                       };
                        if (!string.IsNullOrEmpty(actm.mime_type) &&
                            !string.IsNullOrEmpty(actm.url))
                        {
                            db.InsertOnSubmit(AzureRayaDataContext.TableNames.activityMediaItems, actm);
                            db.SubmitChanges();
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
            }
            return true;
        }
Beispiel #2
0
 public bool SetAppData(string personId, string key, string value, string appId)
 {
     string rowKey = string.Concat(personId, "-", appId, "-", key);
     using (var db = new AzureRayaDataContext())
     {
         if (string.IsNullOrEmpty(value))
         {
             // empty key kind of became to mean "delete data" (was an old orkut hack that became part of the spec spec)
             var ret = new ApplicationSettingRow(personId, rowKey)
                           {
                               application_id = appId,
                               person_id = personId,
                               name = key
                           };
             db.DeleteOnSubmit(ret);
         }
         else
         {
             var ret = db.applicationSettings
                 .Where(x => x.RowKey == rowKey && x.PartitionKey == personId).SingleOrDefault();
             if (ret == null)
             {
                 ret = new ApplicationSettingRow(personId, rowKey)
                           {
                               application_id = appId,
                               person_id = personId,
                               name = key,
                               value = value
                           };
                 db.InsertOnSubmit(AzureRayaDataContext.TableNames.applicationSettings, ret);
             }
             else
             {
                 ret.value = value;
                 db.UpdateOnSubmit(ret);
             }
         }
         db.SubmitChanges();
     }
     
     return true;
 }
Beispiel #3
0
 public bool DeleteAppData(string personId, HashSet<string> keys, string appId)
 {
     using (var db = new AzureRayaDataContext())
     {
         if (keys.Count == 0)
         {
             var ret = db.applicationSettings
                 .Where(x => x.application_id == appId &&
                             x.PartitionKey == personId);
             db.DeleteAllOnSubmit(ret);
         }
         else
         {
             foreach (var key in keys)
             {
                 var ret = db.applicationSettings
                     .Where(x => x.application_id == appId &&
                                 x.PartitionKey == personId &&
                                 x.name == key);
                 db.DeleteOnSubmit(ret);
             }
         }
         db.SubmitChanges();
     }
     return true;
 }
Beispiel #4
0
 public bool DeleteActivities(string userId, string appId, HashSet<string> activityIds)
 {
     var activityList = new List<ActivityRow>();
     using (var db = new AzureRayaDataContext())
     {
         foreach (var id in activityIds)
         {
             var res = db.activities
                 .Where(x => x.id == id &&
                             x.PartitionKey == userId &&
                             x.app_id == appId).SingleOrDefault();
             if (res != null)
             {
                 activityList.Add(res);
             }
         }
         db.DeleteAllOnSubmit(activityList.AsQueryable());
         db.SubmitChanges();
     }
     
     return true;
 }