public Toggle(int idApplication, int idVersion) { //Set default properties //Application ID 1 = ABC if (idApplication == 1) { isButtonBlue = true; isButtonGreen = true; isButtonRed = false; } else { isButtonBlue = true; isButtonGreen = false; isButtonRed = true; } //Get property in database with ID Application and ID Version List <tabControlToggle> list = ControlToggleBLL.GetById(idApplication, idVersion); if (list != null && list.Count() > 0) { //Set new value in property foreach (tabControlToggle objAux in list) { var objResult = this.GetType().GetProperty(objAux.strKey); objResult.SetValue(this, objAux.strValue); } } }
public IHttpActionResult SetToggles(int idApplication, int idVersion, string strToggle, bool value) { //Create object Toggle obj = new Toggle(); var objAux = obj.GetType().GetProperty(strToggle); if (objAux != null) { objAux.SetValue(obj, value); //Verify is existes key in database tabControlToggle objToggle = ControlToggleBLL.GetById(idApplication, idVersion, strToggle); bool bitInsert = false; //Create new object to insert or update in database if (objToggle == null) { objToggle = new tabControlToggle(); bitInsert = true; } objToggle.idApplication = idApplication; objToggle.idVersion = idVersion; objToggle.strKey = strToggle; objToggle.strValue = value; if (bitInsert) { ControlToggleBLL.Insert(objToggle); } else { ControlToggleBLL.Update(objToggle); } } else { obj.msgError = "This property is not defined."; } return(Ok(obj)); }