Exemple #1
0
        public IHttpActionResult PostServer(Server server)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            server.Guid = Guid.NewGuid().ToString();
            server.AuthKey = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 32);

            db.Servers.Add(server);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (ServerExists(server.Id))
                {
                    return Conflict();
                }
                else
                {
                    throw;
                }
            }

            return CreatedAtRoute("ptOSApi", new { id = server.Id }, server);
        }
Exemple #2
0
        public IHttpActionResult PutServer(int id, Server server)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

            db.Entry(server).State = System.Data.Entity.EntityState.Modified;

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

            return StatusCode(HttpStatusCode.NoContent);
        }