public JsonResult CrearVivienda(FormCollection collection) { try { CondominioDAL cond = new CondominioDAL(); VIVIENDA nuevo = new VIVIENDA(); nuevo.ID_CONDOMINIO = int.Parse(collection["condominio"].ToString()); nuevo.NOMBRE_CALLE = collection["direccion"].ToString(); nuevo.NUMERO = collection["numerodire"].ToString(); nuevo.PLANTA_UBICACION = collection["planta"].ToString(); var model = cond.InsertarVivienda(nuevo); if (model) { var result = new { Success = true, Message = "Succes Message", model }; return(Json(result, JsonRequestBehavior.AllowGet)); } else { var result = new { Success = false, Message = "Error Message" }; return(Json(result, JsonRequestBehavior.AllowGet)); } } catch (Exception e) { throw e; } }
public bool InsertarVivienda(VIVIENDA cond) { try { SigescoEntities context = new SigescoEntities(); using (context) { var query = (from a in context.VIVIENDA orderby a.ID_VIVIENDA descending select a.ID_VIVIENDA).FirstOrDefault(); cond.ID_VIVIENDA = query + 1; context.VIVIENDA.Add(cond); context.SaveChanges(); return(true); } } catch (Exception e) { throw e; } }