コード例 #1
0
ファイル: ClientesController.cs プロジェクト: FranPaz/CFenix
        public IHttpActionResult PutCliente(int id, Cliente cliente)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
コード例 #2
0
ファイル: ClientesController.cs プロジェクト: iafar86/CFenix
        public IHttpActionResult PostCliente(Cliente cliente)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Clientes.Add(cliente);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = cliente.Id }, cliente);
        }
コード例 #3
0
ファイル: ClientesController.cs プロジェクト: FranPaz/CFenix
        public HttpResponseMessage PostCliente(Cliente cliente)
        {
            if (!ModelState.IsValid)
            {
                //fpaz: si el modelo enviado con los datos del cliente es incorrecto devuelve un error
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            try
            {
                //fpaz: agrego el nuevo cliente al contexto
                db.Clientes.Add(cliente);
                
                //fpaz: instancio un obj del tipo cuenta corriente y asigno los valores correspondientes para cada campo
                var cuentaCorriente = new CuentaCorriente() {
                    MontoTotal=0,
                    FechaAlta=DateTime.Now,
                    //fpaz: el estado por defecto en la creacion de una cuenta corriente es Activado
                    TipoEstado = (from te in db.TiposEstado
                                 where te.Descripcion == "Activado"
                                 select te).First(),
                    Cliente = cliente //fpaz: asigo el cliente que agregue al contexto antes, en este punto ya deberia tener su id temporal
                };                

                db.Cuentas.Add(cuentaCorriente); //fpaz: agrego la cc al contexto ya deberia tener incluido al cliente
                db.SaveChanges();                 
                return  Request.CreateResponse(HttpStatusCode.OK);
            }
            catch (Exception ex)
            {
                string errorMessage = ex.Message;
                return Request.CreateResponse(HttpStatusCode.BadRequest,errorMessage);                
            }
        }