public static void Grabar(Empleado emple) { //validar campos string erroresValidacion = ""; if (string.IsNullOrEmpty(emple.nom_emple)) { erroresValidacion += "Nombre de empleado es un dato requerido "; } if (string.IsNullOrEmpty(emple.ape_emple)) { erroresValidacion += "Apellido de empleado es un dato requerido "; } if (emple.sueldo <= 0) { erroresValidacion += "Sueldo es un dato requerido "; } if (string.IsNullOrEmpty((emple.fecha_alta).ToString())) { erroresValidacion += "Verifique la fecha "; } if (string.IsNullOrEmpty(emple.id_departamento.ToString())) { erroresValidacion += "Verifique el departamento"; } if (!string.IsNullOrEmpty(erroresValidacion)) { throw new Exception(erroresValidacion); } //grabar registro using (PymesEntities db = new PymesEntities()) { try { if (emple.id_emple > 0) { db.Entry(emple).State = EntityState.Modified; db.SaveChanges(); } else { db.Empleado.Add(emple); db.SaveChanges(); } } catch (Exception ex) { if (ex.ToString().Contains("UK_Nombre")) { throw new ApplicationException("Ya existe otro Trabajador con ese Nombre"); } else { throw; } } } }
public static void Grabar(Articulos DtoSel) { // validar campos string erroresValidacion = ""; if (string.IsNullOrEmpty(DtoSel.Nombre)) { erroresValidacion += "Nombre es un dato requerido; "; } if (DtoSel.Precio == null || DtoSel.Precio == 0) { erroresValidacion += "Precio es un dato requerido; "; } if (!string.IsNullOrEmpty(erroresValidacion)) { throw new Exception(erroresValidacion); } // grabar registro using (PymesEntities db = new PymesEntities()) { try { if (DtoSel.IdArticulo != 0) { db.Entry(DtoSel).State = EntityState.Modified; db.SaveChanges(); } else { db.Articulos.Add(DtoSel); db.SaveChanges(); } } catch (Exception ex) { if (ex.ToString().Contains("UK_Articulos_Nombre")) { throw new ApplicationException("Ya existe otro Artículo con ese Nombre"); } else { throw; } } } }
//************************************************************************************ public static void Grabar(Departamento dpto) { //validar campos string erroresValidacion = ""; if (string.IsNullOrEmpty(dpto.nombre_dpto)) { erroresValidacion += "Descripcion de dpto es un dato requerido "; } //if (dpto.Precio == null || dpto.Precio == 0) // erroresValidacion += "Precio es un dato requerido; "; if (!string.IsNullOrEmpty(erroresValidacion)) { throw new Exception(erroresValidacion); } //grabar registro using (PymesEntities db = new PymesEntities()) { try { if (dpto.id_dpto > 0) { db.Entry(dpto).State = EntityState.Modified; db.SaveChanges(); } else { db.Departamento.Add(dpto); db.SaveChanges(); } } catch (Exception ex) { if (ex.ToString().Contains("UK_Nombre_Dpto")) { throw new ApplicationException("Ya existe otro Departamento con ese Nombre"); } else { throw; } } } }