コード例 #1
0
        public async Task <IHttpActionResult> PutTenUser(int id, TenUser tenUser)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TenUserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #2
0
        private void ChangeUserProfile(int id, string profileUrl)
        {
            TenUserDbContext udb     = new TenUserDbContext();
            TenUser          tenuser = udb.TenUsers.Find(id);

            tenuser.ProfileUrl       = profileUrl;
            udb.Entry(tenuser).State = EntityState.Modified;
            udb.SaveChanges();
        }
コード例 #3
0
        public async Task <IHttpActionResult> GetTenUser(int id)
        {
            TenUser tenUser = await db.TenUsers.FindAsync(id);

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

            return(Ok(tenUser));
        }
コード例 #4
0
        public async Task <IHttpActionResult> PostTenUser(TenUser tenUser)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.TenUsers.Add(tenUser);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = tenUser.UserIndex }, tenUser));
        }
コード例 #5
0
        public async Task <IHttpActionResult> DeleteTenUser(int id)
        {
            TenUser tenUser = await db.TenUsers.FindAsync(id);

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

            db.TenUsers.Remove(tenUser);
            await db.SaveChangesAsync();

            return(Ok(tenUser));
        }