/// <summary> /// Saves or updates a CustomField depending on the ID (uses a generic View Popup by a custommodel binder) /// </summary> /// <param name="fb">Custom Field as an object</param> /// <returns>PopUp if it has errors, close popup if it doesnt</returns> /// <auth>Galaviz Alejos Luis Angel</auth> public ActionResult SaveField([ModelBinder(typeof(CustomFieldBinder))] object fb) { String dataPermissions = Session["Permissions"].ToString(); String dataPermissionsClient = Session["PermissionsClient"].ToString(); bool access = false; bool accessClient = false; // access = getpermissions("users", "r"); access = validatepermissions.getpermissions("custom_fields", "u", dataPermissions); accessClient = validatepermissions.getpermissions("custom_fields", "u", dataPermissionsClient); if (access == true && accessClient == true) { //Validate model if (TryValidateModel(fb)) { //Get table name string tablename = (Session["tablename"].ToString()); //Save or updates field, depending var table = new CustomFieldsTable("MovementFields"); table.saveCustomField(fb); return(null); } else { //In case of error, redraws the popup with error messages return(PartialView("PopUpForm", fb)); } } return(Redirect("~/Home")); }
/// <summary> /// Get table on based on the names of the table /// </summary> /// <param name="tablename">Table name</param> /// <returns>Table with his customFields</returns> /// <author>Galaviz Alejos Luis Angel</author> public ActionResult GetTable(string tablename) { String dataPermissions = Session["Permissions"].ToString(); String dataPermissionsClient = Session["PermissionsClient"].ToString(); bool access = false; bool accessClient = false; // access = getpermissions("users", "r"); access = validatepermissions.getpermissions("custom_fields", "r", dataPermissions); accessClient = validatepermissions.getpermissions("custom_fields", "r", dataPermissionsClient); if (access == true && accessClient == true) { //Get the table based on his name CustomFieldsTable cft = new CustomFieldsTable(tablename); String listArray = cft.GetRows(); JArray list = JsonConvert.DeserializeObject <JArray>(listArray); //Sends hidden input to use on DeleteField and EditField Method ViewData["TableName"] = tablename; //Setea el nombre de la table name en la variable de sesión para el metodo guardar Session["tablename"] = tablename; //Regresa la tabla, con el argumento list, que representa sus rows return(PartialView("Table", list)); } else { return(Redirect("~/Home")); } }
/// <summary> /// Insert a new profile, if is set the idProfile, make an update of that idProfile /// </summary> /// <param name="idProfile"> /// Id of the profile to update. /// </param> /// <returns> /// Returns the view to create a new profile /// </returns> public ActionResult newProfile(string idProfile = null) { bool edit = false; bool editclient = false; String dataPermissions = Session["Permissions"].ToString(); String dataPermissionsClient = Session["PermissionsClient"].ToString(); bool access = false; bool accessClient = false; // access = getpermissions("users", "r"); access = validatepermissions.getpermissions("profiles", "r", dataPermissions); edit = validatepermissions.getpermissions("profiles", "u", dataPermissions); accessClient = validatepermissions.getpermissions("profiles", "r", dataPermissionsClient); editclient = validatepermissions.getpermissions("profiles", "u", dataPermissionsClient); if (Profile != null && (edit == false || editclient == false)) { access = false; accessClient = false; } if (access == true && accessClient == true) { CustomFieldsTable cft = new CustomFieldsTable("CustomFields"); String fieldsArray = cft.GetRows(); JArray fields = JsonConvert.DeserializeObject <JArray>(fieldsArray); if (idProfile != null && idProfile != "null" && idProfile != "") { BsonDocument profile = _profileTable.getRow(idProfile); if (profile != null) { profile.Set("_id", profile.GetElement("_id").Value.ToString()); try { profile.Set("CreatedTimeStamp", profile.GetElement("CreatedTimeStamp").Value.ToString()); } catch (Exception ex) { } string profileJson = profile.ToJson(); ViewData["profile"] = new HtmlString(profileJson); } } List <BsonDocument> profiles = _profileTable.getRows(); ViewBag.profiles = profiles; return(View(fields)); } else { return(Redirect("~/Home")); } }
/// <summary> /// Get CustomField by Id and tablename where it belongs to be updated trought the method SaveField /// </summary> /// <param name="id">Id of the customField</param> /// <param name="tablename">Name of the table where it belongs</param> /// <returns>PopUp with populated Fields</returns> public ActionResult EditField(string id, string tablename) { String dataPermissions = Session["Permissions"].ToString(); String dataPermissionsClient = Session["PermissionsClient"].ToString(); bool access = false; bool accessClient = false; // access = getpermissions("users", "r"); access = validatepermissions.getpermissions("custom_fields", "u", dataPermissions); accessClient = validatepermissions.getpermissions("custom_fields", "u", dataPermissionsClient); if (access == true && accessClient == true) { CustomFieldsTable cft = new CustomFieldsTable("ObjectFields"); String docString = cft.GetRow(id); JObject doc = JsonConvert.DeserializeObject <JObject>(docString); //Reflexing properties ---------------------------------------------------------------------- var model = Activator.CreateInstance(Type.GetType("Rivka.Form.Field." + doc["type"])); if (doc["type"].ToString() == "MultiSelectField") { foreach (SelectListItem list in ((MultiSelectField)model).CustomList) { if (list.Value == doc["listId"].ToString()) { list.Selected = true; } else { list.Selected = false; } } } var props = model.GetType().GetProperties(); foreach (KeyValuePair <String, JToken> element in doc) { var currentprop = (from property in props where property.Name == element.Key select property).FirstOrDefault(); if (currentprop != null) { currentprop.SetValue(model, Convert.ChangeType(element.Value.ToString(), currentprop.PropertyType), null); } } //------------------------------------------------------------------------------------------ return(PartialView("PopUpForm", model)); } else { return(Redirect("~/Home")); } }
/// <summary> /// Get table on based on the names of the table /// </summary> /// <param name="tablename">Table name</param> /// <returns>Table with his customFields</returns> /// <author>Galaviz Alejos Luis Angel</author> public ActionResult GetTable(string tablename) { //Get the table based on his name CustomFieldsTable cft = new CustomFieldsTable("MovementFields"); String list = cft.GetRows(); JArray fieldsArray = JsonConvert.DeserializeObject <JArray>(list); //Sends hidden input to use on DeleteField and EditField Method ViewData["TableName"] = tablename; //Setea el nombre de la table name en la variable de sesión para el metodo guardar Session["tablename"] = tablename; //Regresa la tabla, con el argumento list, que representa sus rows return(PartialView("Table", fieldsArray)); }
/// <summary> /// Deletes a customField /// </summary> /// <param name="id">CustomField Id</param> /// <param name="tablename">Name of the table were the customField belongs</param> /// <author>Galaviz Alejos Luis Angel</author> public void DeleteField(string id, string tablename) { String dataPermissions = Session["Permissions"].ToString(); String dataPermissionsClient = Session["PermissionsClient"].ToString(); bool access = false; bool accessClient = false; // access = getpermissions("users", "r"); access = validatepermissions.getpermissions("custom_fields", "d", dataPermissions); accessClient = validatepermissions.getpermissions("custom_fields", "d", dataPermissionsClient); if (access == true && accessClient == true) { CustomFieldsTable cft = new CustomFieldsTable("MovementFields"); cft.deleteRows(id); } }
/// <summary> /// This method allows to delete several customfields from the db /// </summary> /// <param name="array"> /// It's an array of customs fields ids /// </param> /// <author> /// Luis Gonzalo Quijada Romero /// </author> /// <returns> /// Returns a message string /// </returns> public String deleteFields(List <String> array, string tablename) { String dataPermissions = Session["Permissions"].ToString(); String dataPermissionsClient = Session["PermissionsClient"].ToString(); bool access = false; bool accessClient = false; // access = getpermissions("users", "r"); access = validatepermissions.getpermissions("custom_fields", "r", dataPermissions); accessClient = validatepermissions.getpermissions("custom_fields", "r", dataPermissionsClient); if (access == true && accessClient == true) { CustomFieldsTable cft = new CustomFieldsTable(tablename); if (this.Request.IsAjaxRequest()) //only available with AJAX { try //tryign to delete the fields { if (array.Count == 0) { return(null); //if array is empty there are no fields to delete } foreach (String id in array) //froeach id in the array we must delete the document with that id from the db { cft.deleteRows(id); } return("Borrado"); } catch (Exception e) { return(null); } } return(null); } else { return(null); } }
/// <summary> /// newProfile /// </summary> /// <param name="idProfile"></param> /// <param name="idProcess"></param> public ActionResult newProfile(string idProfile = null, string idProcess = null) { bool upd = false; bool updclient = false; String dataPermissions = Session["Permissions"].ToString(); String dataPermissionsClient = Session["PermissionsClient"].ToString(); bool access = false; bool accessClient = false; // access = getpermissions("users", "r"); access = validatepermissions.getpermissions("profiles", "r", dataPermissions); accessClient = validatepermissions.getpermissions("custom_fields", "r", dataPermissionsClient); upd = validatepermissions.getpermissions("profiles", "u", dataPermissions); updclient = validatepermissions.getpermissions("custom_fields", "u", dataPermissionsClient); if (idProfile != null && (upd == false || updclient == false)) { access = false; accessClient = false; } if (access == true && accessClient == true) { CustomFieldsTable cft = new CustomFieldsTable("MovementFields"); String fieldsArray = cft.GetRows(); JArray fields = JsonConvert.DeserializeObject <JArray>(fieldsArray); if (idProfile != null && idProfile != "null" && idProfile != "") { String rowString = _profileTable.GetRow(idProfile); JObject profile = JsonConvert.DeserializeObject <JObject>(rowString); if (profile != null) { String profileJson = JsonConvert.SerializeObject(profile); ViewData["profile"] = new HtmlString(profileJson); } } if (idProcess != null) { String processString = _processesTable.GetRow(idProcess); JObject process = JsonConvert.DeserializeObject <JObject>(processString); if (process != null) { String processJson = JsonConvert.SerializeObject(process); ViewData["process"] = new HtmlString(processJson); } } String rowArray = _profileTable.GetRows(); JArray profiles = JsonConvert.DeserializeObject <JArray>(rowArray); ViewBag.profiles = profiles; return(View(fields)); } else { return(Redirect("~/Home")); } }
/// <summary> /// Check if the customField name already exist on a table /// </summary> /// <param name="fieldname">Name of the field</param> /// <param name="tablename">Name of the table</param> /// <returns>True if exist, false if it doesnt</returns> public bool CheckIfCustomFieldExist(string fieldname, string tablename) { CustomFieldsTable cft = new CustomFieldsTable("MovementFields"); return(cft.CustomFieldExist(fieldname)); }