Пример #1
0
        public static void RegisterPagelet(this HtmlHelper helper, Pagelet pagelet)
        {
            var  context   = helper.ViewContext.HttpContext;
            bool jsEnabled = context.Request.Cookies["js"] != null && context.Request.Cookies["js"].Value == "true";

            if (!jsEnabled)
            {
                //JavaScript is not enabled, so we write the execution to the output and
                //not register the pagelet
                if (pagelet.Data.Css != null)
                {
                    foreach (string css in pagelet.Data.Css)
                    {
                        helper.IncludeCss(css);
                    }
                }

                pagelet.Execute();
                context.Response.Write(string.Format("<div id=\"{0}\">{1}</div>", pagelet.Container, pagelet.Data.Content));
                context.Response.Flush();
                return;
            }

            List <Pagelet> pagelets = (List <Pagelet>)context.Items["Pagelets"];

            if (pagelets == null)
            {
                pagelets = new List <Pagelet>();
                context.Items["Pagelets"] = pagelets;
            }
            pagelets.Add(pagelet);

            //write pagelet container
            context.Response.Write("<div id=\"" + pagelet.Container + "\"></div>");
        }
        public IHttpActionResult PostPagelet(Pagelet pagelet)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Pagelets.Add(pagelet);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (PageletExists(pagelet.id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = pagelet.id }, pagelet));
        }
        public IHttpActionResult PutPagelet(string id, Pagelet pagelet)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != pagelet.id)
            {
                return(BadRequest());
            }

            db.Entry(pagelet).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PageletExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult GetPagelet(string id)
        {
            Pagelet pagelet = db.Pagelets.Find(id);

            if (pagelet == null)
            {
                return(NotFound());
            }

            return(Ok(pagelet));
        }
        public IHttpActionResult DeletePagelet(string id)
        {
            Pagelet pagelet = db.Pagelets.Find(id);

            if (pagelet == null)
            {
                return(NotFound());
            }

            db.Pagelets.Remove(pagelet);
            db.SaveChanges();

            return(Ok(pagelet));
        }