public ActionResult CreateOET(String idRes, [Bind()] Models.INFOVISITA form, FormCollection collection, string dietas, string genero, bool checkPollo = false, bool checkCarne = false, bool checkCerdo = false, bool checkPescado = false) { int mensaje = -1; if (idRes == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ViewBag.idRes = idRes; var reservacion = BDRegistro.V_RESERVACION.Find(idRes); if (reservacion == null || !reservacion.ANFITRIONA.Equals("01")) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); // 404 } form.CARNE = checkCarne; //checkboxes form.POLLO = checkPollo; form.CERDO = checkCerdo; form.PESCADO = checkPescado; if (form.PERSONA.GENERO == ViewResources.Resources.oet_fem)//si es femenino { form.PERSONA.GENERO = 'F'.ToString(); } else { form.PERSONA.GENERO = 'M'.ToString(); //masculino } form.ID_RESERVACION = idRes; form.CEDULA = form.PERSONA.CEDULA; form.ESTADO = "A"; if (ModelState.IsValid) { var db = BDRegistro; string nominst = (string)collection["PERSONA.INSTITUCIONI.FULL_NAME"]; V_INSTITUCION inst = BDRegistro.V_INSTITUCION.Where(x => String.Equals(x.FULL_NAME, nominst)).FirstOrDefault(); form.PERSONA.INSTITUCION = (inst == null) ? (int?)null : inst.CAT_INSTITUCION; form.PERSONA.INSTITUCIONI = inst; string nompais = (string)collection["PERSONA.PAISI.NOMBRE"].ToUpper();; V_PAISES pais = BDRegistro.V_PAISES.Where(x => String.Equals(x.NOMBRE, nompais)).FirstOrDefault(); form.PERSONA.PAIS = (pais == null) ? null : pais.ISO; form.PERSONA.PAISI = pais; string gentpais = (string)collection["PERSONA.NACIONALIDADI.GENTILICIO"].ToUpper(); V_PAISES nacion = BDRegistro.V_PAISES.Where(x => String.Equals(x.GENTILICIO, gentpais)).FirstOrDefault(); form.PERSONA.NACIONALIDAD = (nacion == null) ? null : nacion.ISO; form.PERSONA.NACIONALIDADI = nacion; string insti = (string)collection["PERSONA.INSTITUCIONI.FULL_NAME"].ToUpper(); V_INSTITUCION institucion = BDRegistro.V_INSTITUCION.Where(x => String.Equals(x.FULL_NAME, gentpais)).FirstOrDefault(); if (institucion != null) { form.PERSONA.INSTITUCION = institucion.CAT_INSTITUCION; } form.PERSONA.INSTITUCIONI = institucion; form.CEDULA = form.PERSONA.CEDULA; var cedulaP = BDRegistro.PERSONA.Find(form.PERSONA.CEDULA); db.INFOVISITA.Add(form); if (cedulaP != null) { db.Entry(cedulaP).State = EntityState.Detached; db.PERSONA.Attach(form.PERSONA); db.Entry(form.PERSONA).State = EntityState.Modified; } try { db.SaveChanges(); //se guarda la información } catch (Exception e) { mensaje = 0; return(RedirectToAction("CreateOET", new { idRes, mensaje })); } // return RedirectToAction("Index"); } mensaje = 1; return(RedirectToAction("CreateOET", new { idRes, mensaje })); }
public ActionResult CreateESINTRO(String idRes, [Bind()] Models.INFOVISITA form, FormCollection collection, string dietas, string genero, bool checkPollo = false, bool checkCarne = false, bool checkCerdo = false, bool checkPescado = false) { int mensaje = -1; if (idRes == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ViewBag.idRes = idRes; var reservacion = BDRegistro.V_RESERVACION.Find(idRes); if (reservacion == null || !reservacion.ANFITRIONA.Equals("02")) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); // 404 } form.CARNE = checkCarne; //checkboxes form.POLLO = checkPollo; form.CERDO = checkCerdo; form.PESCADO = checkPescado; form.ID_RESERVACION = idRes; if (genero == ViewResources.Resources.oet_fem) // si es femenino { form.PERSONA.GENERO = 'F'.ToString(); } else { form.PERSONA.GENERO = 'M'.ToString(); //es masculino } if (dietas == ViewResources.Resources.oet_sinrestr) //si selecciona sin restricciones de dieta { form.DIETA = "No Restriction"; } else { if (dietas.Equals(ViewResources.Resources.oet_vege))//vegetariano { form.DIETA = "Vegetarian"; } else { form.DIETA = "Vegan"; //si seleciona dieta vegana } } form.ESTADO = "A"; form.CEDULA = form.PERSONA.CEDULA; if (ModelState.IsValid) { var db = BDRegistro; string nompais = (string)collection["PERSONA.PAISI.NOMBRE"].ToUpper(); V_PAISES pais = BDRegistro.V_PAISES.Where(x => String.Equals(x.NOMBRE, nompais)).FirstOrDefault(); form.PERSONA.PAIS = (pais == null) ? null : pais.ISO; form.PERSONA.PAISI = pais; string gentpais = (string)collection["PERSONA.NACIONALIDADI.GENTILICIO"].ToUpper(); V_PAISES nacion = BDRegistro.V_PAISES.Where(x => String.Equals(x.GENTILICIO, gentpais)).FirstOrDefault(); form.PERSONA.NACIONALIDAD = (nacion == null) ? null : nacion.ISO; form.PERSONA.NACIONALIDADI = nacion; form.CEDULA = form.PERSONA.CEDULA; var cedulaP = BDRegistro.PERSONA.Find(form.PERSONA.CEDULA); db.INFOVISITA.Add(form); if (cedulaP != null) { db.Entry(cedulaP).State = EntityState.Detached; db.PERSONA.Attach(form.PERSONA); db.Entry(form.PERSONA).State = EntityState.Modified; } try { db.SaveChanges(); } catch (Exception e) { mensaje = 0; return(RedirectToAction("CreateESINTRO", new { idRes, mensaje })); } } mensaje = 1; return(RedirectToAction("CreateESINTRO", new { idRes, mensaje })); }