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 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; } } } }