public ActionResult Create(infAvaliacaoViewModel avaliacao) { if (ModelState.IsValid) { var qtdAvals = db.avaliacoes.Count(q => q.medicos_idMedico == avaliacao.idMedico); if (qtdAvals != 0) { var somaNotas = db.avaliacoes.Where(m => m.medicos_idMedico == avaliacao.idMedico). GroupBy(m => m.medicos_idMedico).Select(n => n.Sum(m => m.notas)).Single(); int total = Convert.ToInt16(somaNotas); total += avaliacao.nota; qtdAvals++; avaliacao.media = Convert.ToDouble(total / qtdAvals); } else { avaliacao.media = avaliacao.nota; } avaliacoes aval = new avaliacoes(); aval.medicos_idMedico = avaliacao.idMedico; aval.notas = avaliacao.nota; aval.media = avaliacao.media; aval.data = DateTime.Today; aval.comentarios = avaliacao.comentario; aval.pacientes_idPaciente = Convert.ToInt16(Session["idUsuario"]); db.avaliacoes.Add(aval); db.SaveChanges(); return(RedirectToAction("Index", "consultas")); } return(View(avaliacao)); }
public ActionResult DeleteConfirmed(int id) { avaliacoes avaliacoes = db.avaliacoes.Find(id); db.avaliacoes.Remove(avaliacoes); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "idAvaliacao,notas,comentarios,media,data,medicos_idMedico")] avaliacoes avaliacoes) { if (ModelState.IsValid) { db.Entry(avaliacoes).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.medicos_idMedico = new SelectList(db.medicosSet, "idMedico", "nome", avaliacoes.medicos_idMedico); return(View(avaliacoes)); }
// GET: avaliacoes/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } avaliacoes avaliacoes = db.avaliacoes.Find(id); if (avaliacoes == null) { return(HttpNotFound()); } return(View(avaliacoes)); }
// GET: avaliacoes/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } avaliacoes avaliacoes = db.avaliacoes.Find(id); if (avaliacoes == null) { return(HttpNotFound()); } ViewBag.medicos_idMedico = new SelectList(db.medicosSet, "idMedico", "nome", avaliacoes.medicos_idMedico); return(View(avaliacoes)); }