public ActionResult obtenerDetalle(string id, string fecha1 = null, string fecha2 = null) { using (hotelesEntidad db = new hotelesEntidad()) { if (String.IsNullOrEmpty(id)) { return(null); } int cod = 0; bool isValid = Int32.TryParse(id, out cod); var s = db.habitacion.Find(cod); codigos co = new codigos(); co.codigo = s.codigo; co.precio = s.precio; co.hotel = s.hotel.nombre; co.clase = Listado.getLista(s.clase); co.iva = s.hotel.categoria.iva; DateTime f1 = new DateTime(); DateTime f2 = new DateTime(); try { f1 = Convertir.aTimeStamp(Convert.ToInt64(fecha1)); f2 = Convertir.aTimeStamp(Convert.ToInt64(fecha2)); } catch (Exception e) { co.total = (co.precio * co.iva) / 100 + co.precio; return(Json(co, JsonRequestBehavior.AllowGet)); } TimeSpan ts = new TimeSpan(); TimeSpan hora2 = new TimeSpan(12, 0, 0); ts = f2.Subtract(f1); //ts2 = a2.Subtract(a1); co.tiempoExtra = ts.Days + ((ts.Days == 1) ? " Día":" Dias"); co.tiempoExtra += " con " + ts.Hours + ((ts.Hours == 1) ? " Hora" : " Horas"); co.total = (((ts.Days == 0) ? co.precio * 1 : co.precio * ts.Days) * co.iva) / 100 + co.precio; return(Json(co, JsonRequestBehavior.AllowGet)); } }