public static Result guardar(int id, int maestroAnexosId, int usuarioId, string nombreOpcion) { Result r = ValidateSession.validarSession(usuarioId, HttpContext.Current.Session["usuarioId"]); if (r.error != "") { return(r); } OpcionesMaestroAnexos objEntity = new OpcionesMaestroAnexos(); objEntity.id = id; objEntity.maestroAnexosId = maestroAnexosId; objEntity.usuarioId = usuarioId; objEntity.nombreOpcion = nombreOpcion; try { OpcionesMaestroAnexosController omac = new OpcionesMaestroAnexosController(); return(omac.guardarOpcionesMaestroAnexos(objEntity)); } catch (Exception ex) { return(new Result() { error = ex.Message, id = 0, tipoAlerta = "warning" }); } }
public Result eliminarOpcionesMaestroAnexos(int opcionesmaestroanexosId, int usuarioId) { if (existeRegistro(opcionesmaestroanexosId)) { Result result = new Result() { error = "" }; result = ValidateSession.validarOperacionesForm("OpcionesMaestroAnexos", "Eliminar", usuarioId); if (result.error != null && result.error != "") { return(result); } OpcionesMaestroAnexos registroEliminar = entity.OpcionesMaestroAnexos.Where(x => x.id == opcionesmaestroanexosId).SingleOrDefault(); entity.OpcionesMaestroAnexos.Remove(registroEliminar); MoldeTrasabilidad.trasabilidadObject((registroEliminar as object), "OpcionesMaestroAnexos", "Eliminado", usuarioId, "AplicacionMolde"); try { entity.SaveChanges(); return(new Result { error = result.error, id = opcionesmaestroanexosId }); } catch (Exception e) { return(new Result { error = e.Message, id = 0, tipoAlerta = "warning" }); } } return(new Result { error = "" }); }
private Result validarAtributos(OpcionesMaestroAnexos registro) { if (registro.maestroAnexosId == 0) { return(new Result { error = "Seleccione el maestro anexo asociado.", tipoAlerta = "warning" }); } if (registro.nombreOpcion == "") { return(new Result { error = "Digite el nombre de la opción.", tipoAlerta = "warning" }); } return(new Result() { error = "" }); }
public Result guardarOpcionesMaestroAnexos(OpcionesMaestroAnexos registro) { Result result = new Result() { error = "" }; result = validarAtributos(registro); if (result.error != null && result.error != "") { return(result); } if (existeRegistro(registro.id)) { result = ValidateSession.validarOperacionesForm("OpcionesMaestroAnexos", "Editar", registro.usuarioId); if (result.error != null && result.error != "") { return(result); } int opcionesmaestroanexosId = registro.id; OpcionesMaestroAnexos registroEditar = entity.OpcionesMaestroAnexos.Where(x => x.id == opcionesmaestroanexosId).SingleOrDefault(); entity.Entry(registroEditar).CurrentValues.SetValues(registro); try { entity.SaveChanges(); return(new Result { error = "" }); } catch (Exception e) { return(new Result { error = e.Message, id = 0, tipoAlerta = "warning" }); } } else { result = ValidateSession.validarOperacionesForm("OpcionesMaestroAnexos", "Nuevo", registro.usuarioId); if (result.error != null && result.error != "") { return(result); } entity.OpcionesMaestroAnexos.Add(registro); try { entity.SaveChanges(); return(new Result { error = result.error, id = registro.id }); } catch (Exception e) { return(new Result { error = e.Message, id = 0, tipoAlerta = "warning" }); } } }