public ActionResult Carga(PreviaModel model) { if (ModelState.IsValid) { gafest2014Entities ctx = new gafest2014Entities(); IQueryable<PREVIA> test = ctx.PREVIA.Where(previa => previa.USERNAME == ContextHelper.LoggedUser.USERNAME); if (test == null || test.Count<PREVIA>() == 0) { PREVIA p = new PREVIA(); p.FOTO = ImageHelper.PostedFileToByteArray(model.Imagen); p.TITULO = model.Titulo; p.ID = ImageHelper.GetPreviaNextNumber(); p.USERNAME = ContextHelper.LoggedUser.USERNAME; p.VALID = "Y"; ctx.PREVIA.Add(p); ctx.SaveChanges(); ctx.Dispose(); return RedirectToAction("Index"); } else { throw new ApplicationException("Solo se permite la carga de una previa por usuario"); } } else { return RedirectToAction("Index", model); } }
// // GET: /Previa/ public ActionResult Index(PreviaModel model) { ViewBag.ult_prev = ctx.PREVIA.OrderByDescending(prev => prev.ID).Take(3).ToList<PREVIA>(); ViewBag.ranking = ctx.PREVIA.OrderByDescending(prev => prev.VOTOPREVIA.Count()).Take(3).ToList<PREVIA>(); return View(); }