Пример #1
0
        public IHttpActionResult PutKpi(int id, Kpi kpi)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != kpi.KpiID)
            {
                return BadRequest();
            }

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
Пример #2
0
        public IHttpActionResult PostKpi(Kpi kpi)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            kpi.type = db.KpiTypes.Find(kpi.type.KpiTypeID);
            db.Kpis.Add(kpi);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = kpi.KpiID }, kpi);
        }