public IHttpActionResult DeleteEmoEmotion(int id) { EmoEmotion emoEmotion = db.EmoEmotions.Find(id); if (emoEmotion == null) { return(NotFound()); } db.EmoEmotions.Remove(emoEmotion); db.SaveChanges(); return(Ok(emoEmotion)); }
// GET: EmoEmotions/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } EmoEmotion emoEmotion = db.EmoEmotions.Find(id); if (emoEmotion == null) { return(HttpNotFound()); } return(View(emoEmotion)); }
// GET: EmoEmotions/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } EmoEmotion emoEmotion = db.EmoEmotion.Find(id); if (emoEmotion == null) { return(HttpNotFound()); } ViewBag.EmoFaceId = new SelectList(db.EmoFaces, "Id", "Id", emoEmotion.EmoFaceId); return(View(emoEmotion)); }
private ObservableCollection <EmoEmotion> ProcessEmotions(EmotionScores scores, EmoFace emoFace) { var emotionList = new ObservableCollection <EmoEmotion>(); var properties = scores.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); var filterProperties = properties.Where(p => p.PropertyType == typeof(float)); var emoType = EmoEmotionEnum.Undertermined; foreach (var prop in filterProperties) { if (!Enum.TryParse <EmoEmotionEnum>(prop.Name, out emoType)) { emoType = EmoEmotionEnum.Undertermined; } var emoEmotion = new EmoEmotion(); emoEmotion.Score = (float)prop.GetValue(scores); emoEmotion.EmotionType = emoType; emoEmotion.Face = emoFace; emotionList.Add(emoEmotion); } return(emotionList); }
// Se crea el metodo para private ObservableCollection <EmoEmotion> ProcessEmotions(EmotionScores scores, EmoFace emoface) { // Se instancia una variable lista de EmoEmotion para Almacenar los valores a las emociones var emotionList = new ObservableCollection <EmoEmotion>(); // con GetType se muestro toda la informacion que tiene scores,Con GetProperties Me devuelve todas // las propiedades de scores y en los parametros de Getproperties para que no me devuelva todas las // las propiedades le especifico cuales quiero traer. El | es un or binario ya que estamos haciendo // intercambio con una enumeracion. El Instance es para que no me devuelva los campos estaticos var properties = scores.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); // Se filtran los valores recividos que sean de tipo float de properties var filterProperties = properties.Where(p => p.PropertyType == typeof(float)); // Se Crea una variable para los valores que no estan definidos para que se almacenen en el var emotype = EmoEmotionEnum.Undetermined; // Se recorre filterProperties para irle agregando los valores de puntuacion foreach (var prop in filterProperties) { // Se convierte los parametros de la Emumeracion EmoEmotionEnum EN un valor equivalente // a un Enumerable y si no los convierte el valor recivido se convierte en if (!Enum.TryParse <EmoEmotionEnum>(prop.Name, out emotype)) { emotype = EmoEmotionEnum.Undetermined; } // Se instancia EmoEmotion var emoEmotion = new EmoEmotion(); // Se le agregan los valores a los atributos de EmoEmotion emoEmotion.Score = (float)prop.GetValue(scores); // Se le almacena un valor Indeterminado a emoEmotion.EmotionType emoEmotion.EmotionType = emotype; // Se le almacenan las propiedades definidas en el metodo anterior emoEmotion.Face = emoface; // Se va llenando la lista con los valores almacenados emotionList.Add(emoEmotion); } // Se returno la Lista que se lleno return(emotionList); }
/* * La funcion extraera cada emocion de la variable scores para transformarla en un * array de EmoEmotion * scores: es la respuesta con cada valor de emociones en una sola variable * */ private ObservableCollection <EmoEmotion> ProcessEmotions(EmotionScores scores, EmoFace emoFace) { // se usara reflection var emotionList = new ObservableCollection <EmoEmotion>(); // Obtengo los campos del objeto // BindingFlags.Public: para obtener solo las propiedades publicas // BindingFlags.Instance: Para que no me devuelva los campos estaticos var properties = scores.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); // como properties es collection, puedo usar linq //var filterProperties = properties.Where(p => p.PropertyType == typeof(float)); var filterProperties = from p in properties where p.PropertyType == typeof(float) select p; // variable que se usara para tener el tipo de emotion var emotype = EmoEmotionEnum.Undetermined; foreach (var prop in filterProperties) { // trato de determinar el valor de la enumeracion if (!Enum.TryParse <EmoEmotionEnum>(prop.Name, out emotype)) { emotype = EmoEmotionEnum.Undetermined; } var emoEmotion = new EmoEmotion(); // obtengo el valor de la emotion emoEmotion.Score = (float)prop.GetValue(scores); emoEmotion.EmotionType = emotype; emoEmotion.Face = emoFace; emotionList.Add(emoEmotion); } return(emotionList); }
private ObservableCollection <EmoEmotion> ProcessEmotions(EmotionScores scores, EmoFace emoface) { //Creamos una lista observable de emociones var emotionList = new ObservableCollection <EmoEmotion>(); //Devuelve el tipo y las propiedades publicas y que son parte de una instancia var properties = scores.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); //Las propiedades son generias, las filtramos por el tipo Float que es el tipo //de dato que necesitamos de Scores var filterProperties = properties.Where(p => p.PropertyType == typeof(float)); //Incia la iteracion var emotype = EmoEmotionEnum.Undetermined; foreach (var prop in filterProperties) { //este metodo recibe dos parametros, 1 un string de valor, y otro un valor de salida del Enum if (!Enum.TryParse <EmoEmotionEnum>(prop.Name, out emotype)) { emotype = EmoEmotionEnum.Undetermined; } //Instancia del EmoEmotion var emoEmotion = new EmoEmotion(); //Agregamos el valor que se itera de las filtraciones emoEmotion.Score = (float)prop.GetValue(scores); emoEmotion.EmotionType = emotype; emoEmotion.Face = emoface; //Lo agregamos emotionList.Add(emoEmotion); } //Retornamos la lista return(emotionList); }
private ObservableCollection <EmoEmotion> ProcessEmotion(EmotionScores scores, EmoFace emoFace) { var emotionList = new ObservableCollection <EmoEmotion>(); // Reflection // permite aaceder a los metodos propios de los componentes en tiempo de ejecucion // (que sean publicos o propios de la instancia) // traer todas las propiedades var properties = scores.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); // linq para hacer query en una lista y filtrar tofas las propiedades float // var filterProperties = from p in properties where p.PropertyType == typeof(float) select p; var filterProperties = properties.Where(p => p.PropertyType == typeof(float)); var emoType = EmoEmotionEnum.Undertermined; foreach (var prop in filterProperties) { // asignar el valor en un enum // convierte el parametro en una opcion del enumerador ENUM -> retorna booleano Enum.TryParse <EmoEmotionEnum>(prop.Name, out emoType); var emoEmotion = new EmoEmotion() { Score = (float)prop.GetValue(scores), EmotionType = emoType, Face = emoFace }; emotionList.Add(emoEmotion); } return(emotionList); }