示例#1
0
        public async Task<IHttpActionResult> PostOperatorAgent(OperatorAgent operatorAgent)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            operatorAgent.OperatorAgentId = Guid.NewGuid();
            db.OperatorAgents.Add(operatorAgent);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (OperatorAgentExists(operatorAgent.OperatorAgentId))
                {
                    return Conflict();
                }
                else
                {
                    throw;
                }
            }

            return CreatedAtRoute("DefaultApi", new { id = operatorAgent.OperatorAgentId }, operatorAgent);
        }
示例#2
0
        public async Task<IHttpActionResult> PutOperatorAgent(Guid id, OperatorAgent operatorAgent)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != operatorAgent.OperatorAgentId)
            {
                return BadRequest();
            }

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }