Ejemplo n.º 1
0
        // POST odata/EmployeeTypes
        public async Task<IHttpActionResult> Post(EmployeeType employeetype)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.EmployeeTypes.Add(employeetype);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (EmployeeTypeExists(employeetype.EmployeeTypeId))
                {
                    return Conflict();
                }
                else
                {
                    throw;
                }
            }

            return Created(employeetype);
        }
Ejemplo n.º 2
0
        // PUT odata/EmployeeTypes(5)
        public async Task<IHttpActionResult> Put([FromODataUri] int key, EmployeeType employeetype)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (key != employeetype.EmployeeTypeId)
            {
                return BadRequest();
            }

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

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

            return Updated(employeetype);
        }