Esempio n. 1
0
 public ActionResult Create([Bind(Include = "id,typeId,name,label,columns,parameters,description")] Procedure procedure)
 {
     try {
         procedure.authorId = User.Identity.Name;
         db.Procedures.Add(procedure);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     } catch {
         return(View(procedure));
     }
 }
Esempio n. 2
0
        public ActionResult Create([Bind(Include = "id,authorId,data")] Log icarusLog)
        {
            if (ModelState.IsValid)
            {
                db.Logs.Add(icarusLog);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(icarusLog));
        }
Esempio n. 3
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
                            ));
            }
        }
Esempio n. 4
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
            }
        }
Esempio n. 5
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));
            }
        }