public IHttpActionResult PutSesionTrabajo(int id, SesionTrabajo sesionTrabajo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != sesionTrabajo.IdSesion) { return(BadRequest()); } db.Entry(sesionTrabajo).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { throw; } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetSesionTrabajo(int id) { SesionTrabajo sesionTrabajo = db.SesionTrabajo.Find(id); if (sesionTrabajo == null) { return(NotFound()); } return(Ok(sesionTrabajo)); }
public IHttpActionResult PostSesionTrabajo(SesionTrabajo sesionTrabajo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.SesionTrabajo.Add(sesionTrabajo); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = sesionTrabajo.IdSesion }, sesionTrabajo)); }
public static void Grabar(SesionTrabajo DtoSel) { // validar campos string erroresValidacion = ""; if (string.IsNullOrEmpty(DtoSel.Tareas)) { erroresValidacion += "Nombre es un dato requerido; "; } if (!string.IsNullOrEmpty(erroresValidacion)) { throw new Exception(erroresValidacion); } // grabar registro using (pav2_72622Entities db = new pav2_72622Entities()) { try { if (DtoSel.IdSesion != 0) { db.Entry(DtoSel).State = EntityState.Modified; db.SaveChanges(); } else { db.SesionTrabajo.Add(DtoSel); db.SaveChanges(); } } catch (Exception ex) { if (ex.ToString().Contains("UK_SesionTrabajo_Tareas")) { throw new ApplicationException("Ya existe otra Sesion con esas Tareas"); } else { throw; } } } }
public static SesionTrabajo ADOBuscarPorId(int IdSesion) { //ref ADO; Recuperar cadena de conexión de web.config string CadenaConexion = System.Configuration.ConfigurationManager.ConnectionStrings["PymesAdo"].ConnectionString; //ref ADO; objetos conexion, comando, parameters y datareader SqlConnection cn = new SqlConnection(); cn.ConnectionString = CadenaConexion; SesionTrabajo sesionTrabajo = null; try { cn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = cn; cmd.CommandText = "select * from SesionTrabajo c where c.IdSesion = @IdSesion"; cmd.Parameters.Add(new SqlParameter("@IdSesion", IdSesion)); SqlDataReader dr = cmd.ExecuteReader(); // con el resultado cargar una entidad //ref ADO; generar un objeto entidad if (dr.Read()) { sesionTrabajo = new SesionTrabajo(); sesionTrabajo.IdSesion = (int)dr["IdSesion"]; sesionTrabajo.Tareas = dr["Tareas"].ToString(); if (dr["PrecioHora"] != DBNull.Value) { sesionTrabajo.PrecioHora = (decimal)dr["PrecioHora"]; } if (dr["IdProyecto"] != DBNull.Value) { sesionTrabajo.IdProyecto = (int)dr["IdProyecto"]; } if (dr["CantTareas"] != DBNull.Value) { sesionTrabajo.CantTareas = (int)dr["CantTareas"]; } if (dr["FechaDesde"] != DBNull.Value) { sesionTrabajo.FechaDesde = (DateTime)dr["FechaDesde"]; } if (dr["FechaHasta"] != DBNull.Value) { sesionTrabajo.FechaHasta = (DateTime)dr["FechaHasta"]; } if (dr["Activo"] != DBNull.Value) { sesionTrabajo.Activo = (bool)dr["Activo"]; } } dr.Close(); } catch (Exception) { throw; } finally { if (cn.State == ConnectionState.Open) { cn.Close(); } } return(sesionTrabajo); }