Beispiel #1
0
        public IHttpActionResult PostProform(ProformViewModel newProform)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            Proform proform = Mapper.Map<ProformViewModel, Proform>(newProform);
            var client = db.People.OfType<Client>().FirstOrDefault(p => p.Id == newProform.ClientId);
            proform.Client = client;
            db.Proforms.AddOrUpdate(proform);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = proform.Id }, new { data = proform });
        }
Beispiel #2
0
        public IHttpActionResult PutProform(int id, ProformViewModel existingProform)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

            Proform proform = Mapper.Map<ProformViewModel, Proform>(existingProform);
            var client = db.People.OfType<Client>().FirstOrDefault(p => p.Id == existingProform.ClientId);
            proform.Client = client;
            db.Entry(proform).State = EntityState.Modified;

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

            return StatusCode(HttpStatusCode.NoContent);
        }