Esempio n. 1
0
        public IHttpActionResult PutWebContent(int id, WebsiteTemplateProject.Models.WebContent webContent)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 2
0
        public IHttpActionResult PostWebContent(WebsiteTemplateProject.Models.WebContent webContent)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.WebContents.Add(webContent);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = webContent.Id }, webContent));
        }
Esempio n. 3
0
        public IHttpActionResult DeleteWebContent(int id)
        {
            WebsiteTemplateProject.Models.WebContent webContent = db.WebContents.Find(id);
            if (webContent == null)
            {
                return(NotFound());
            }

            db.WebContents.Remove(webContent);
            db.SaveChanges();

            return(Ok(webContent));
        }
Esempio n. 4
0
        public WebsiteTemplateProject.Models.WebContent UpsertWebContent(WebsiteTemplateProject.Models.WebContent webContent, GlobalContentDBEntities db)
        {
            using (db)
            {
                if (webContent.Id == default(int))
                {
                    //Default settings when first creating text
                    if (webContent.TextBody != null)
                    {
                        webContent.textMobile = webContent.TextBody;
                        webContent.textTablet = webContent.TextBody;
                        webContent.textLaptop = webContent.TextBody;

                        webContent.textAlign = "center";
                    }

                    //Default settings when first creating background image


                    db.WebContents.Add(webContent);
                }
                else
                {
                    db.Entry(webContent).State = EntityState.Modified;
                }

                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    var newException = new FormattedDbEntityValidationException(e);
                    throw newException;
                }


                return(webContent);
            }
        }