public async Task <ActionResult> Edit(int clientId, CardioInfo cardioInfo)
        {
            if (ModelState.IsValid)
            {
                db.Entry(cardioInfo).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index", new { clientId = clientId }));
            }
            return(View(cardioInfo));
        }
        // GET: CardioInfo/Edit/5
        public async Task <ActionResult> Edit(int?id, int clientId)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CardioInfo cardioInfo = await db.CardioInfo.FindAsync(id);

            ViewBag.clientId = clientId;
            if (cardioInfo == null)
            {
                return(HttpNotFound());
            }
            return(View(cardioInfo));
        }
        public async Task <ActionResult> Create(int clientId, CardioInfo cardioInfo)
        {
            if (ModelState.IsValid)
            {
                fichas_medicas fm = db.fichas_medicas.Where(m => m.cliente_id == clientId).Include(m => m.cardio).OrderByDescending(m => m.created_at).FirstOrDefault();
                fm.cardio.Add(cardioInfo);
                fm.updated_at = Utilities.CurrentDate.getNow();

                db.Entry(fm).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index", new { clientId = clientId }));
            }

            return(View(cardioInfo));
        }
        public async Task <ActionResult> Global(int id)
        {
            int daysInMonth = DateTime.DaysInMonth(CurrentDate.getNow().Year, CurrentDate.getNow().Month);

            DateTime today    = CurrentDate.getNow();
            DateTime firstDay = new DateTime(today.Year, today.Month, 1);
            DateTime lastDay  = new DateTime(today.Year, today.Month, daysInMonth);

            // Info General
            clientes client = await db.clientes
                              .Where(m => m.id_alt == id)
                              .Include(m => m.nutricionistas.usuarios)
                              .FirstOrDefaultAsync();

            // Info Programa
            programa_clientes program = await db.programa_clientes
                                        .Where(m => m.cliente_id == client.id_alt && m.fecha_inicio <= today && m.fecha_fin >= today)
                                        .Include(m => m.programa)
                                        .Include(m => m.horario.sala.local)
                                        .OrderBy(m => m.fecha_fin)
                                        .FirstOrDefaultAsync();

            ViewBag.ProgramId = program != null?program.id.ToString() : "";

            ViewBag.ProgramName     = program != null ? program.programa.nombre : "";
            ViewBag.ProgramInitDate = program != null?program.fecha_inicio.ToShortDateString() : "";

            ViewBag.ProgramEndDate = program != null?program.fecha_fin.ToShortDateString() : "";

            ViewBag.ProgramSchedule = program != null?program.horario.hora.ToString() : "";

            ViewBag.Gym = program != null ? program.horario.sala.local.nombre : "";

            // Info Notas del cliente
            List <clientes_notas> notes = await db.clientes_notas.Where(n => n.idCliente == id).OrderByDescending(n => n.created_at).Take(15).ToListAsync();

            ViewBag.ClientNotes = notes;

            //// Info Calendario.
            //List<pesos_medidas> clientPyM = await db.pesos_medidas.Where(m => m.clienteId == id && m.created_at >= firstDay && m.created_at <= lastDay).ToListAsync();
            //List<clientes_asistencia> clientAssistance = await db.clientes_asistencia.Where(m => m.clienteId == id && m.fecha >= firstDay && m.fecha <= lastDay).ToListAsync();
            //List<clientes_congelamientos> clientFreezing = await db.clientes_congelamientos.Where(m => m.clienteId == id && m.fecha_desde >= firstDay).ToListAsync();
            //List<citas> clientConsults = await db.citas.Where(m => m.cliente_id == id && m.fecha >= firstDay && m.fecha <= lastDay).ToListAsync();

            // Info Nutricion.

            ViewBag.AssignedNutritionist = client.nutricionistas.usuarios.nombres + " " + client.nutricionistas.usuarios.apellidos;
            if (program != null)
            {
                // Info Ficha Medica
                fichas_medicas medicalHistory = await db.fichas_medicas.Where(m => m.programa_id == program.id).Include(m => m.cardio).FirstOrDefaultAsync();

                ViewBag.MedicalId = "No ha sido creada.";
                ViewBag.Cardio    = "No se han ingresado datos.";
                if (medicalHistory != null)
                {
                    int clientCurrMedicalHistoryIdCode = 10000000 + medicalHistory.id;
                    ViewBag.MedicalId = clientCurrMedicalHistoryIdCode.ToString("FS#");

                    if (medicalHistory.cardio != null)
                    {
                        CardioInfo lastCardioResults = medicalHistory.cardio.OrderByDescending(m => m.fecha).FirstOrDefault();
                        if (lastCardioResults.cardiologia_aprobacion == CardioSuittable.Apto)
                        {
                            ViewBag.Cardio = CardioSuittable.Apto.ToString();
                        }
                        else
                        {
                            ViewBag.Cardio = CardioSuittable.NoApto.ToString();
                        }
                    }
                }

                // Info Dieta
                clientes_dietas clientDiet = await db.clientes_dietas.Where(m => m.programa_clientes_id == program.id).OrderByDescending(m => m.created_at).FirstOrDefaultAsync();

                if (clientDiet != null)
                {
                    int dietCode = 10000000 + clientDiet.id;
                    ViewBag.DietCode = dietCode.ToString("D#");
                }
            }

            // Info Ventas

            venta_usuarios usrSales = await db.venta_usuarios
                                      .Where(m => m.cliente_id == client.id_alt)
                                      .OrderByDescending(m => m.created_at)
                                      .FirstOrDefaultAsync();

            if (usrSales != null)
            {
                usuarios usr = await db.vendedores.Where(v => v.usuario_id == usrSales.vendedor_id).Include(v => v.usuarios).Select(v => v.usuarios).FirstOrDefaultAsync();

                ViewBag.Seller      = usr.nombres + " " + usr.apellidos;
                ViewBag.LastTicket  = usrSales.numero_boleta;
                ViewBag.LastRenewal = usrSales.fecha_inicio.ToShortDateString();

                semanas_precios weeks = db.semanas_precios.Where(s => s.id == usrSales.semanas_precio_id).FirstOrDefault();

                int boughtWeeks = weeks.cantidad_semanas;
                ViewBag.BoughtWeeks = boughtWeeks.ToString();
                int usedWeeks = await GetUsedWeeks(ClientId : client.id_alt, LastSaleId : usrSales.id);

                ViewBag.UsedWeeks    = usedWeeks;
                ViewBag.PendingWeeks = boughtWeeks - usedWeeks;
            }

            //ViewBag.venta_usuario = db.venta_usuarios.Where(vu => vu.cliente_id == id).FirstOrDefault();
            //ViewBag.programa_cliente = db.programa_clientes.Where(pc => pc.cliente_id == id).FirstOrDefault();

            //ViewBag.calPyM = clientPyM;
            //ViewBag.calAsist = clientAssistance;
            //ViewBag.calFrz = clientFreezing;
            //ViewBag.calCitas = clientConsults;
            //

            //ViewBag.cardioApt = cardioApt;
            //ViewBag.foto = Convert.ToBase64String(cliente.foto);

            return(View(client));
        }
Пример #5
0
        // GET: FichasMedicas/Create
        public ActionResult Create(int clienteId)
        {
            clientes          cl    = db.clientes.Where(c => c.id_alt == clienteId).FirstOrDefault();
            DateTime          today = CurrentDate.getNow();
            programa_clientes prgCl = db.programa_clientes.Where(m => m.cliente_id == cl.id_alt && m.fecha_inicio <= today && m.fecha_fin >= today).FirstOrDefault();

            fichas_medicas fm = db.fichas_medicas.Where(m => m.cliente_id == cl.id_alt).Include(m => m.controles).Include(m => m.regimen_alimentacion).Include(m => m.cardio).Include(m => m.laboratorio).OrderByDescending(m => m.created_at).FirstOrDefault();

            ViewBag.currentCardioControl = null;
            if (fm != null && fm.cardio.Count > 0)
            {
                CardioInfo lastCardioInfoInserted = fm.cardio.OrderByDescending(m => m.fecha).First();

                TimeSpan dateDif = CurrentDate.getNow().Subtract(lastCardioInfoInserted.fecha);

                if (dateDif <= new TimeSpan(180, 0, 0, 0))
                {
                    ViewBag.currentCardioControl = lastCardioInfoInserted;
                }
            }

            ViewBag.currentLabControl = null;
            if (fm != null && fm.laboratorio.Count > 0)
            {
                LabResults lastLabInfoInserted = fm.laboratorio.OrderByDescending(m => m.fecha).First();

                TimeSpan dateDif = CurrentDate.getNow().Subtract(lastLabInfoInserted.fecha);

                if (dateDif <= new TimeSpan(180, 0, 0, 0))
                {
                    ViewBag.currentLabControl = lastLabInfoInserted;
                }
            }

            if (fm != null && fm.controles.Count > 0)
            {
                List <ControlesNutricionales> cn = fm.controles;
                List <string> cnRows             = new List <string>();
                foreach (ControlesNutricionales c in cn)
                {
                    string row = GetNutritionalControlString(c: c);
                    cnRows.Add(row);
                    controlsCount++;
                }
                controlsCount       = 0;
                ViewBag.controlsLst = cnRows;
            }

            if (fm != null && fm.regimen_alimentacion.Count > 0)
            {
                List <FeedingRegime> fr     = fm.regimen_alimentacion;
                List <string>        frList = new List <string>();
                foreach (FeedingRegime f in fr)
                {
                    string row = GetFoodRegimeString(f: f);
                    frList.Add(row);
                    foodRegimesCount++;
                }
                foodRegimesCount   = 0;
                ViewBag.regimenLst = frList;
            }

            ViewBag.clientId  = cl.id_alt;
            ViewBag.programId = prgCl.programa_id;

            return(View());
        }