예제 #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>
 /// Select all elements
 /// </summary>
 /// <param name="ctx"></param>
 /// <param name="id"></param>
 /// <returns>A collection of elements</returns>
 public override IEnumerable <Container> selectAll(ObjectDBContext ctx)
 {
     return(ctx.ImageGalleries.Where(FilterAllowed()));
 }
예제 #4
0
 /// <summary>
 /// Select a single element
 /// </summary>
 /// <param name="ctx"></param>
 /// <param name="id"></param>
 /// <returns>A single ImageGallery Element</returns>
 public override Container select(ObjectDBContext ctx, int id)
 {
     return(ctx.ImageGalleries.AsQueryable().Single(FilterById(id)));
 }
예제 #5
0
 /// <summary>
 /// Select a single element
 /// </summary>
 /// <param name="ctx"></param>
 /// <returns></returns>
 public override IEnumerable <Container> selectAll(ObjectDBContext ctx)
 {
     return(ctx.Thumbnails.Where(FilterAllowed()));
 }
예제 #6
0
 /// <summary>
 /// Select a single element
 /// </summary>
 /// <param name="ctx"></param>
 /// <param name="id"></param>
 /// <returns></returns>
 public override Container select(ObjectDBContext ctx, int id)
 {
     return(ctx.Thumbnails.AsQueryable().Single(FilterById(id)));
 }
예제 #7
0
 /// <summary>
 /// Select a single element
 /// </summary>
 /// <param name="ctx"></param>
 /// <param name="id"></param>
 /// <returns></returns>
 public override IEnumerable <Container> selectAll(ObjectDBContext ctx)
 {
     return(ctx.ClassIndexes.Where(FilterAllowed()));
 }
예제 #8
0
 /// <summary>
 /// Select a single element
 /// </summary>
 /// <param name="ctx"></param>
 /// <param name="id"></param>
 /// <returns></returns>
 public override IEnumerable <Container> selectAll(ObjectDBContext ctx)
 {
     return(ctx.FormTextAreas.Where(FilterAllowed()));
 }
예제 #9
0
        [HttpPost, ValidateAntiForgeryToken, Authorize(Roles = "Dev,Admin")] //Authorize
        public virtual async Task <ActionResult> Disable(int id)
        {
            string message = "";

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

                // Verify ownership and process deletion
                if (model.getAuthorId() == User.Identity.Name)
                {
                    List <string> columns = new List <string>();
                    columns.Add("id");
                    columns.Add("className");
                    columns.Add("label");

                    List <Param> parameters = new List <Param>();
                    parameters.Add(new Param(1, "id", id));

                    // Only delete if this Container does not have parents
                    Procedure procedure = new Procedure("ICARUS.GetContainerParents", columns, parameters);

                    List <Dictionary <string, object> > records = this.Call(procedure);
                    if (records.Count <= 1)  // Should only exist in MAIN or nowhere
                    // Set new values
                    {
                        int result = 0;
                        if (model != null)
                        {
                            model.status           = -1;
                            model.dateLastModified = DateTime.UtcNow.ToLocalTime();
                            //model.updateContainerModel(formPost);

                            // 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 disabled " + this.className + " (" + model.id + "," + id + ")"
                                            ), JsonRequestBehavior.AllowGet));
                        }
                        else
                        {
                            return(Json(new Payload(
                                            0, "Failed to disable " + this.className + "(" + id + ").  The request returned null."
                                            ), JsonRequestBehavior.AllowGet));
                        }
                    }
                    else
                    {
                        return(Json(new Payload(
                                        0, "Failed to disable " + this.className + "(" + id + ").  This Container is still in use."
                                        ), JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    message = "Failed to disable " + this.className + "(" + id
                              + ")\nYou do not have permissions to modify this " + this.className;

                    return(Json(new Payload(0, message), JsonRequestBehavior.AllowGet));
                }
            } catch (Exception e) {
                return(Json(new Payload(0, e, e.Message), JsonRequestBehavior.AllowGet));
            }
        }
예제 #10
0
 /// <summary>
 /// Selects all records that are available to this user
 /// </summary>
 /// <param name="ctx"></param>
 /// <returns></returns>
 public abstract IEnumerable <Container> selectAll(ObjectDBContext ctx);
예제 #11
0
 /// <summary>
 /// Selects a single Container element
 /// </summary>
 /// <returns></returns>
 public abstract Container select(ObjectDBContext ctx, int id);
예제 #12
0
 /// <summary>
 /// Select a single Main element
 /// </summary>
 /// <param name="ctx"></param>
 /// <param name="id"></param>
 /// <returns></returns>
 public override Container select(ObjectDBContext ctx, int id)
 {
     return(ctx.FormElementGroups.AsQueryable().Single(FilterById(id)));
 }