コード例 #1
0
        /// <summary>
        /// Sets the value of the target object based on the given formPost values
        /// </summary>
        /// <param name="formPost">FormPost</param>
        /// <returns>A Json Object</returns>
        public override async Task <ActionResult> Set(FormPost formPost)
        {
            try {
                // Extract values from FormPost
                formPost.resultsToXml();
                int id = formPost.parseInt("id", -1);

                // Retrieve the record from the database
                ObjectDBContext ctx   = getObjectDbContext();
                var             model = select(ctx, id);

                // Set new values
                int result = 0;
                if (model != null)
                {
                    if (model.authorId == User.Identity.Name || model.shared == 1)
                    {
                        model.status = 1;

                        model.updateContainerModel(formPost);
                        model.dateLastModified = DateTime.UtcNow.ToLocalTime();

                        // Save the object
                        db.dbSets[this.className].Add(model);                             // ctx.Containers.Add(model);
                        ctx.Entry(model).State = System.Data.Entity.EntityState.Modified; // Critical
                        result = ctx.SaveChanges();

                        // Return the success response along with the message body
                        return(Json(new Payload(
                                        1, this.className, model
                                        //"Successfully set " + this.className + " (" + model.id + "," + id + ")"
                                        ), JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json(new Payload(
                                        0, "You are not authorized to modify this " + this.className + "(" + id + ")"
                                        ), JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    return(Json(new Payload(
                                    0, "Failed to retrieve " + this.className + "(" + id + ").  The request returned null."
                                    ), JsonRequestBehavior.AllowGet));
                }
            } catch (Exception e) {
                return(Json(new Payload(
                                0, e,
                                "Unknown exception for " + this.className + "<br><br>"
                                + e.Message.ToString()), JsonRequestBehavior.AllowGet
                            ));
            }
        }
コード例 #2
0
        /// <summary>
        /// Sets the value of the target object based on the given formPost values
        /// </summary>
        /// <param name="formPost"></param>
        /// <returns></returns>
        public override async Task <ActionResult> Set(FormPost formPost)
        {
            try {
                // Extract values from FormPost
                formPost.resultsToXml();
                int id       = formPost.parseInt("id", -1);
                int shared   = formPost.parseInt("shared", 0);
                int isPublic = formPost.parseInt("isPublic", 0);

                // Retrieve the record from the database
                ObjectDBContext ctx   = getObjectDbContext();
                FormPost        model = ctx.FormPosts.Single(m =>
                                                             m.id == id && (m.authorId == User.Identity.Name || m.shared == 1)
                                                             );

                formPost.setXml();
                formPost.resultsToXml();

                // Set new values
                int result = 0;
                model.xmlResults  = formPost.xmlResults;
                model.jsonResults = formPost.jsonResults;
                model.formId      = formPost.formId;
                model.shared      = shared;
                model.isPublic    = isPublic;

                // Save the object
                ctx.FormPosts.Add(model);
                ctx.Entry(model).State = System.Data.Entity.EntityState.Modified; // Critical
                result = ctx.SaveChanges();

                // Return the success response along with the message body
                return(Json(new Payload(1, "FORMPOST", model)));                                                  //, JsonRequestBehavior.AllowGet // "Successfully set FORMPOST (" + model.id + "," + id + ")"
            } catch (Exception e) {
                return(Json(new Payload(0, e, "Unknown exception for FORMPOST<br><br>" + e.Message.ToString()))); // JsonRequestBehavior.AllowGet
            }
        }
コード例 #3
0
 /// <summary>
 /// Sets Container Model values based on the given FormPost
 /// </summary>
 /// <param name="formPost"></param>
 public void updateContainerModel(FormPost formPost)
 {
     formPost.resultsToXml();
     this.subsections      = formPost.parseString("subsections", "0");
     this.label            = formPost.parseString("label");
     this.id               = formPost.parseInt("id", -1);
     this.attributesId     = formPost.parseInt("attributesId");
     this.dataId           = formPost.parseInt("dataId");
     this.metaId           = formPost.parseInt("metaId");
     this.shared           = formPost.parseInt("shared");
     this.isPublic         = formPost.parseInt("isPublic");
     this.dateLastModified = DateTime.UtcNow.ToLocalTime();
 }