示例#1
0
        public async Task <IHttpActionResult> PutClass(string id, Class @class)
        {
            ComputerEntities db = new ComputerEntities();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != @class.ClassCode)
            {
                return(BadRequest());
            }

            db.Entry(@class).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#2
0
        public async Task <IHttpActionResult> PostClass(Class @class)
        {
            ComputerEntities db = new ComputerEntities();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Classes.Add(@class);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (ClassExists(@class.ClassCode))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = @class.ClassCode }, @class));
        }
示例#3
0
        public async Task <IHttpActionResult> DeleteClass(string id)
        {
            ComputerEntities db     = new ComputerEntities();
            Class            @class = await db.Classes.FindAsync(id);

            if (@class == null)
            {
                return(NotFound());
            }

            db.Classes.Remove(@class);
            await db.SaveChangesAsync();

            return(Ok(@class));
        }