Exemple #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;
        }
Exemple #2
0
 private Activity ConvertToActivity(ActivityRow row)
 {
     var act = new Activity(row.id, row.person_id);
     act.streamTitle = "activities";
     act.title = row.title;
     act.body = row.body;
     act.postedTime = row.created;
     act.mediaItems = GetMediaItems(row.id);
     return act;
 }