Exemplo n.º 1
0
        public ActionResult SendPoint([FromBody] PointsRequest request)
        {
            using (new DatabaseSwitcher(Factory.GetDatabase("master")))
            {
                var team = Sitecore.Context.Database.GetItem(new ID(request.TeamId));
                var judgeValuationTemplate = Sitecore.Context.Database.GetItem(new ID("{4CC5BB60-689D-46F1-83CB-348EA5DA3950}"));
                var folderTemplate         = Sitecore.Context.Database.GetItem(new ID("{A87A00B1-E6DB-45AB-8B54-636FEC3B5523}"));

                Sitecore.Data.Items.Item judgesFolder = null;
                if (team.Children["Judges"] == null)
                {
                    judgesFolder = team.Add("Judges", new TemplateItem(folderTemplate));
                }
                else
                {
                    judgesFolder = team.Children["Judges"];
                }

                var judge = judgesFolder.Add(Sitecore.Context.User.LocalName, new TemplateItem(judgeValuationTemplate));

                using (new EditContext(judge))
                {
                    judge["Point"]    = request.Point;
                    judge["Comments"] = request.Comment;
                }

                return(Json("Ok", JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Executes the action with the specified <paramref name="data" />.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="formSubmitContext">The form submit context.</param>
        /// <returns>
        ///   <c>true</c> if the action is executed correctly; otherwise <c>false</c>
        /// </returns>
        protected override bool Execute(string data, FormSubmitContext formSubmitContext)
        {
            Assert.ArgumentNotNull(formSubmitContext, nameof(formSubmitContext));
            Dictionary <string, object> values = new Dictionary <string, object>();

            foreach (IViewModel fields in formSubmitContext.Fields)
            {
                try
                {
                    KeyValuePair <string, object> fieldData = GetFieldData(fields);
                    values.Add(fieldData.Key, fieldData.Value);
                }
                catch (Exception ex)
                {
                    Sitecore.Diagnostics.Log.Error(ex.Message, ex, typeof(RegisterTeam));
                }
            }

            //Disable the Security
            using (new SecurityDisabler())
            {
                Database master = Sitecore.Configuration.Factory.GetDatabase("master");
                if (master != null)
                {
                    //Here you need the Parent Item (new item will be child of this item)
                    Sitecore.Data.Items.Item parentItem = master.GetItem(new ID("{F9B025E2-42E6-489A-98A8-F660834062E2}"));

                    //Get the template for the new item
                    TemplateItem teamTemplate = master.GetTemplate(Templates.Team.Id);

                    if (teamTemplate != null)
                    {
                        //Now, use Parent item to add a new item underneath and pass the item name and template as parameter
                        Item newItem = parentItem?.Add("NewItem", teamTemplate);

                        try
                        {
                            if (newItem != null)
                            {
                                newItem.Editing.BeginEdit();
                                newItem.Editing.EndEdit();
                            }
                        }
                        catch
                        {
                            newItem.Editing.CancelEdit();
                        }
                    }
                }
            }

            return(true);
        }