コード例 #1
0
        public IHttpActionResult PutHomePage(int id, HomePage homePage)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #2
0
        public HomePage UpsertHomePage(HomePage homePage, HomePageDBEntities1 db)
        {
            using (db)
            {
                if (homePage.UserID == default(int))
                {
                    db.HomePages.Add(homePage);
                }
                else
                {
                    db.Entry(homePage).State = EntityState.Modified;
                }

                db.SaveChanges();
                return(homePage);
            }
        }