public ActionResult <LinkBox> EditLinkBoxMethod(LinkBox link_box, int admin_id, string admin_token, int site_id)
        {
            LinkBox queried_link_box;

            try{
                queried_link_box = dbQuery.QueryLinkBoxById(link_box.link_box_id);
            }catch {
                JsonFailure f = new JsonFailure($"link_box Id: {link_box.link_box_id} not found.");
                return(StatusCode(400, f));
            }

            //verify and change
            if (authenticator.VerifyAdminForLeaf(admin_id, queried_link_box.site_id, admin_token))
            {
                DataPlan data_plan;
                try{
                    data_plan = _dataLimiter.ValidateDataPlanB(admin_id, queried_link_box, link_box);
                }catch (System.ArgumentException e) {
                    return(StatusCode(400, e.Message));
                }

                LinkBox changed_portrait = dbQuery.EditLinkBox(link_box);
                _dataLimiter.UpdateDataPlan(data_plan);
                return(changed_portrait);
            }
            else
            {
                return(StatusCode(400, "Invalid credentials."));
            }
        }
 public ActionResult <LinkBox> GetLinkBoxMethod(int link_box_id)
 {
     try{
         LinkBox link_box = dbQuery.QueryLinkBoxById(link_box_id);
         return(link_box);
     }catch {
         return(StatusCode(400, "Component Not Found"));
     }
 }
Beispiel #3
0
    /// <summary>自动为添加按钮附加参数,Request中,只要是当前实体成员的参数,否附加上去</summary>
    void AutoAddParamForAdd()
    {
        if (Request.QueryString == null || Request.QueryString.Count < 1)
        {
            return;
        }
        if (EntityType == null)
        {
            return;
        }

        LinkBox lb = ControlHelper.FindControlByField <LinkBox>(Page, "lbAdd");

        if (lb == null)
        {
            return;
        }

        StringBuilder    sb = new StringBuilder();
        IEntityOperate   op = EntityFactory.CreateOperate(EntityType);
        HashSet <String> hs = new HashSet <string>(op.FieldNames, StringComparer.OrdinalIgnoreCase);

        foreach (String item in Request.QueryString.Keys)
        {
            // 仅接受实体类成员
            if (!hs.Contains(item))
            {
                continue;
            }

            if (sb.Length > 0)
            {
                sb.Append("&");
            }
            sb.AppendFormat("{0}={1}", item, Request.QueryString[item]);
        }
        if (sb.Length > 0)
        {
            if (!lb.Url.Contains("?"))
            {
                lb.Url += "?" + sb;
            }
            else
            {
                lb.Url += "&" + sb;
            }
        }
    }
        public ActionResult <JsonResponse> PostLinkBoxMethod(NewLinkBoxDto _NewLinkBox, int admin_id, string admin_token)
        {
            LinkBox NewLinkBox = new LinkBox();

            NewLinkBox.title        = _NewLinkBox.title;
            NewLinkBox.content      = _NewLinkBox.content;
            NewLinkBox.url          = _NewLinkBox.url;
            NewLinkBox.link_display = _NewLinkBox.link_display;


            NewLinkBox.priority  = _NewLinkBox.priority;
            NewLinkBox.site_id   = _NewLinkBox.site_id;
            NewLinkBox.byte_size = NewLinkBox.FindCharLength();

            if (authenticator.VerifyAdminForLeaf(admin_id, NewLinkBox.site_id, admin_token))
            {
                List <string> errors = authenticator.ValidateIncomingComponent(NewLinkBox);
                if (errors.Count == 0)
                {
                    DataPlan data_plan;
                    try{
                        data_plan = _dataLimiter.ValidateComponentAdditionForDataPlan(admin_id, NewLinkBox);
                    }catch (System.ArgumentException e) {
                        return(StatusCode(400, e.Message));
                    }

                    dbQuery.AddLinkBox(NewLinkBox);
                    _dataLimiter.UpdateDataPlan(data_plan);
                    JsonResponse r = new JsonSuccess("Link Box posted sucessfully!");
                    return(r);
                }
                else
                {
                    return(StatusCode(400, errors));
                }
            }
            else
            {
                return(StatusCode(400, "Invalid Token. Stranger Danger."));
            }
        }
 public ActionResult <JsonResponse> DeleteAuthenticatedSiteComponentMethod(ComponentReference Component)
 {
     if (Component.component_type == "p_box")
     {
         try{
             ParagraphBox paragraph_box = dbQuery.DeleteParagraphBox(Component.component_id);
             Site         parent_site   = dbQuery.QueryFeaturelessSiteById(paragraph_box.site_id);
             _dataLimiter.RemoveFromDataPlan(paragraph_box, parent_site.admin_id);
             JsonResponse r = new JsonSuccess("Paragraph box deleted sucessfully!");
             return(r);
         }catch {
             JsonFailure f = new JsonFailure($"Unable to find paragraph box id {Component.component_id}");
             return(StatusCode(400, f));
         }
     }
     else if (Component.component_type == "image")
     {
         try{
             Image image       = dbQuery.DeleteImage(Component.component_id);
             Site  parent_site = dbQuery.QueryFeaturelessSiteById(image.site_id);
             _dataLimiter.RemoveFromDataPlan(image, parent_site.admin_id);
             JsonResponse r = new JsonSuccess("Image deleted sucessfully!");
             return(r);
         }catch {
             JsonFailure f = new JsonFailure($"Unable to find image id {Component.component_id}");
             return(StatusCode(400, f));
         }
     }
     else if (Component.component_type == "portrait")
     {
         try{
             Portrait portrait    = dbQuery.DeletePortrait(Component.component_id);
             Site     parent_site = dbQuery.QueryFeaturelessSiteById(portrait.site_id);
             _dataLimiter.RemoveFromDataPlan(portrait, parent_site.admin_id);
             JsonResponse r = new JsonSuccess("Portrait component deleted sucessfully!");
             return(r);
         }catch {
             JsonFailure f = new JsonFailure($"Unable to find portrait id {Component.component_id}");
             return(StatusCode(400, f));
         }
     }
     else if (Component.component_type == "2c_box")
     {
         try{
             TwoColumnBox two_column_box = dbQuery.DeleteTwoColumnBox(Component.component_id);
             Site         parent_site    = dbQuery.QueryFeaturelessSiteById(two_column_box.site_id);
             _dataLimiter.RemoveFromDataPlan(two_column_box, parent_site.admin_id);
             JsonResponse r = new JsonSuccess("Two Column Box component deleted sucessfully!");
             return(r);
         }catch {
             JsonFailure f = new JsonFailure($"Unable to find two column box id {Component.component_id}");
             return(StatusCode(400, f));
         }
     }
     else if (Component.component_type == "link_box")
     {
         try{
             LinkBox link_box    = dbQuery.DeleteLinkBox(Component.component_id);
             Site    parent_site = dbQuery.QueryFeaturelessSiteById(link_box.site_id);
             _dataLimiter.RemoveFromDataPlan(link_box, parent_site.admin_id);
             JsonResponse r = new JsonSuccess("Link Box component deleted sucessfully!");
             return(r);
         }catch {
             JsonFailure f = new JsonFailure($"Unable to find link box id {Component.component_id}");
             return(StatusCode(400, f));
         }
     }
     else
     {
         JsonFailure f = new JsonFailure("Type mismatch. Type does not match any known components.");
         return(StatusCode(400, f));
     }
 }
Beispiel #6
0
 public ActionResult <LinkBox> EditLinkBox([FromBody] LinkBox link_box, int admin_id, string admin_token, int site_id)
 {
     return(methods.EditLinkBoxMethod(link_box, admin_id, admin_token, site_id));
 }