public ActionResult Create([Bind(Include = "Id,UtenteId,Cuidador,EntidadeReferenciadora,DiagnosticoClinico,DataDeAlta,CriteriosDeTriagem,DependenciaAVD,Desnutricao,Deteorioracao,ProblemasSensoriais,DCronicas,NCCD,NTC,CP,NE,AND,ECE,CuidadorDetalhes,IRS,Criacao")] Referenciacao referenciacao)
        {
            if (ModelState.IsValid)
            {
                db.Dados.Add(referenciacao);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(referenciacao));
        }
Exemplo n.º 2
0
        public ActionResult Login(string username, string password)
        {
            Medicos            med   = (Medicos)db.meds.Where(c => c.Name.Equals(username) && c.Password.Equals(password)).SingleOrDefault();
            Enfermeiros        enf   = (Enfermeiros)db.enfs.Where(c => c.Name.Equals(username) && c.Password.Equals(password)).SingleOrDefault();
            AssistentesSociais asist = (AssistentesSociais)db.assis.Where(c => c.Name.Equals(username) && c.Password.Equals(password)).SingleOrDefault();

            if (med != null)
            {
                var token = Crypto.HashPassword(med.Password);
                db.tokens.Add(new Tokens {
                    Role = "Médico", UserId = med.Id, Token = token, crt = DateTime.Now
                });
                db.SaveChanges();
                Session["role"] = token;
                return(RedirectToAction("Index", "Medicos"));
            }

            else if (enf != null)
            {
                var token = Crypto.HashPassword(enf.Password);
                db.tokens.Add(new Tokens {
                    Role = "Enfermeiro", UserId = enf.Id, Token = token, crt = DateTime.Now
                });
                db.SaveChanges();
                Session["role"] = token;
                return(RedirectToAction("Index", "Enfermeiros"));
            }
            else if (asist != null)
            {
                var token = Crypto.HashPassword(asist.Password);
                db.tokens.Add(new Tokens {
                    Role = "Assistente", UserId = asist.Id, Token = token, crt = DateTime.Now
                });
                db.SaveChanges();
                Session["role"] = token;
                return(RedirectToAction("Index", "Assistente"));
            }

            return(View());
        }
Exemplo n.º 3
0
        public ActionResult Index(string SearchString = null)
        {
            foreach (var d in db.tokens)
            {
                DateTime aux = d.crt;
                if (aux.AddHours(2).CompareTo(DateTime.Now) < 0)
                {
                    db.tokens.Remove(d);
                }
            }
            ;

            db.SaveChanges();

            if (Session["role"] == null)
            {
                return(RedirectToAction("Login", "Home"));
            }

            Tokens token = (Tokens)db.tokens.ToList().Where(c => c.Token.Equals((String)Session["role"])).SingleOrDefault();

            if (token == null || token.Role != "Assistente")
            {
                return(RedirectToAction("Login", "Home"));
            }

            int id = token.UserId;


            if (SearchString != null || SearchString == "")
            {
                List <Utente>   lista  = db.uts.ToList().Where(c => c.Name.Contains(SearchString) || c.HSE.Contains(SearchString)).ToList();
                MedicosViewPage dados1 = new MedicosViewPage {
                    utentes = lista, refeDone = db.Dados.ToList().Where(c => {
                        for (int i = 0; i < lista.Count; i++)
                        {
                            if (lista[i].Id == c.UtenteId && c.AssistOk)
                            {
                                return(true);
                            }
                        }
                        return(false);
                    }).ToList().Take(20).ToList(),
                    refeNot = db.Dados.ToList().Where(c => {
                        for (int i = 0; i < lista.Count; i++)
                        {
                            if (lista[i].Id == c.UtenteId && c.AssistOk == false)
                            {
                                return(true);
                            }
                        }
                        return(false);
                    }).ToList().Take(20).ToList(),
                    enfe = db.enfs.ToList(),
                    meds = db.meds.ToList()
                };

                return(View(dados1));
            }
            MedicosViewPage dados2 = new MedicosViewPage {
                utentes = db.uts.ToList(), refeDone = db.Dados.ToList().Where(c => c.AssistOk).Take(20).ToList(), refeNot = db.Dados.ToList().Where(c => c.AssistOk == false).Take(20).ToList(), enfe = db.enfs.ToList(), meds = db.meds.ToList()
            };

            return(View(dados2));
        }