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

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

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
Пример #2
0
        public IHttpActionResult PostFact(Fact fact)
        {
            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}

            fact.CreatedAt = DateTime.Now;
            fact.UpdatedAt = DateTime.Now;

            db.Facts.Add(fact);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = fact.Id }, fact);
        }