Esempio n. 1
0
        public IHttpActionResult PostClient(ClientViewModel newClient)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            Client client = Mapper.Map<ClientViewModel, Client>(newClient);

            db.People.Add(client);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = client.Id }, new { data = client });
        }
Esempio n. 2
0
        public IHttpActionResult PutClient(int id, ClientViewModel existingClient)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != existingClient.Id)
            {
                return BadRequest();
            }
            Client client = Mapper.Map<ClientViewModel, Client>(existingClient);
            db.Entry(client).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ClientExists(id))
                {
                    return NotFound();
                }
                return BadRequest();
            }

            return CreatedAtRoute("DefaultApi", new { id = client.Id }, new { data = client });
            //return StatusCode(HttpStatusCode.NoContent);
        }