public async Task <IHttpActionResult> GetPlan(int id)
        {
            Plan p = await db.Planes.FindAsync(id);

            if (p == null)
            {
                return(NotFound());
            }

            DTO_Plan plan = new DTO_Plan()
            {
                Id            = p.Id,
                Descripcion   = p.Descripcion,
                FechaCreacion = p.FechaCreacion,
                ClienteId     = p.ClienteId,
                Cliente       = p.Cliente.Nombre
            };

            return(Ok(plan));
        }
        public async Task <IHttpActionResult> PostPlan(DTO_Plan plan)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Plan nuevoPlan = new Plan()
            {
                Descripcion   = plan.Descripcion,
                FechaCreacion = DateTime.Now,
                ClienteId     = plan.ClienteId
            };

            db.Planes.Add(nuevoPlan);
            await db.SaveChangesAsync();

            plan.Id = nuevoPlan.Id;

            return(CreatedAtRoute("DefaultApi", new { id = plan.Id }, plan));
        }
        public async Task <IHttpActionResult> DeletePlan(int id)
        {
            Plan plan = await db.Planes.FindAsync(id);

            if (plan == null)
            {
                return(NotFound());
            }

            DTO_Plan eliminaPlan = new DTO_Plan()
            {
                Id            = plan.Id,
                Descripcion   = plan.Descripcion,
                FechaCreacion = plan.FechaCreacion,
                ClienteId     = plan.ClienteId
            };

            db.Planes.Remove(plan);
            await db.SaveChangesAsync();

            return(Ok(eliminaPlan));
        }
        public async Task <IHttpActionResult> PutPlan(int id, DTO_Plan plan)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            Plan actualizaPlan = await db.Planes.FindAsync(id);

            actualizaPlan.Descripcion = plan.Descripcion;
            actualizaPlan.ClienteId   = plan.ClienteId;

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PlanExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }