示例#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;
        }
示例#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;
 }