public ActionResult Create(FormCollection collection) { if (ModelState.IsValid) { var primero = Convert.ToInt32(collection["PrimerNumero"].ToString()); var segundo = Convert.ToInt32(collection["SegundoNumero"].ToString()); var tercero = Convert.ToInt32(collection["TercerNumero"].ToString()); if (primero != segundo && segundo != tercero && primero != tercero) { var data = collection["Sorteos"].ToString(); var sorteo = db.Sorteos.Find(Convert.ToInt32(collection["Sorteos"].ToString())); var objGanadores = new Ganadores { PrimerNumero = Convert.ToInt32(collection["PrimerNumero"].ToString()), SegundoNumero = Convert.ToInt32(collection["SegundoNumero"].ToString()), TercerNumero = Convert.ToInt32(collection["TercerNumero"].ToString()), Sorteos = sorteo }; db.Ganadores.Add(objGanadores); db.SaveChanges(); notificarGanadores(sorteo.Id, objGanadores.PrimerNumero, 1); notificarGanadores(sorteo.Id, objGanadores.SegundoNumero, 2); notificarGanadores(sorteo.Id, objGanadores.TercerNumero, 3); Ganadores.updateSorteo(db, sorteo.Id); TempData["Success"] = "Ganadores registrados correctamente."; return(RedirectToAction("Index")); } TempData["Error"] = "Los números ganadores no pueden ser iguales"; return(RedirectToAction("Index")); } return(RedirectToAction("Index")); }