Example #1
0
        public static Item InstallActivity(UserStorageContext userContext, SuggestionsStorageContext suggestionsContext, User user, Folder category, Guid? subCategory, GalleryActivity galleryActivity)
        {
            // get activity from context
            var activity = suggestionsContext.GalleryActivities.FirstOrDefault(ga => ga.ID == galleryActivity.ID);
            if (activity == null)
                return null;

            if (category == null)
            {
                var galleryCategory = suggestionsContext.GalleryCategories.FirstOrDefault(gc => gc.ID == activity.CategoryID);
                if (galleryCategory == null)
                    return null;
                category = CreateCategory(userContext, user, galleryCategory.Name);
            }

            return InstallActivity(userContext, suggestionsContext, category, subCategory, activity);
        }
Example #2
0
 public ActionResult InstallActivity(GalleryActivity activity, Folder category)
 {
     var jsResult = new JsInstallResult();
     Item item = GalleryProcessor.InstallActivity(this.StorageContext, Storage.NewSuggestionsContext, this.CurrentUser, category, null, activity);
     if (item != null)
     {
         jsResult.FolderID = item.FolderID;
         jsResult.ItemID = item.ID;
     }
     else
     {
         jsResult.StatusCode = HttpStatusCode.NotFound;
     }
     JsonResult result = new JsonResult();
     result.Data = jsResult;
     return result;
 }
Example #3
0
        public static Item InstallActivity(UserStorageContext userContext, SuggestionsStorageContext suggestionsContext, Folder category, Guid? subCategory, GalleryActivity galleryActivity)
        {
            Item result = null;
            try
            {
                // deserialize the definition
                var def = JsonSerializer.Deserialize<ActivityDefinition>(galleryActivity.Definition);

                // create the new item corresponding to the activity
                DateTime now = DateTime.Now;
                var activity = new Item()
                {
                    ID = Guid.NewGuid(),
                    Name = def.Name,
                    FolderID = category.ID,
                    ParentID = subCategory,
                    UserID = category.UserID,
                    ItemTypeID = SystemItemTypes.Activity,
                    IsList = true,
                    Status = StatusTypes.Active,
                    Created = now,
                    LastModified = now,
                };
                result = activity;

                // make this the last activity in the (sub)category
                float sortOrder = (userContext.Items.Any(i => i.UserID == category.UserID && i.FolderID == category.ID &&
                                                              i.ItemTypeID == SystemItemTypes.Activity && (subCategory.HasValue ? i.ParentID == subCategory : i.ParentID == null)) ?
                    userContext.Items.Where(i => i.UserID == category.UserID && i.FolderID == category.ID &&
                                                 i.ItemTypeID == SystemItemTypes.Activity && (subCategory.HasValue ? i.ParentID == subCategory : i.ParentID == null)).
                    Select(i => i.SortOrder).
                    Max() :
                    0f) + 1000f;
                activity.SortOrder = sortOrder;

                // set ActivityID of gallery activity this Item is created from
                activity.GetFieldValue(ExtendedFieldNames.ActivityID, true).Value = galleryActivity.ID.ToString();

                // if provided, set the default cadence of the activity
                if (def.Recurrence != null)
                    activity.GetFieldValue(FieldNames.Repeat, true).Value = def.Recurrence.ToString();

                // if provided, set the status
                if (def.Status != null)
                    activity.Status = def.Status;

                userContext.Items.Add(activity);
                userContext.SaveChanges();

                // install all the steps for the activity
                sortOrder = 1;
                foreach (var step in def.Steps)
                {
                    InstallStep(userContext, category, activity.ID, step, sortOrder);
                    sortOrder += 1;
                }
            }
            catch (Exception ex)
            {
                TraceLog.TraceException("InstallActivity failed", ex);
                return result;
            }
            return result;
        }