public ActionResult AgregarProducto(int id) { string[] datos = Storage.Instance.ListadoFarmacos[id - 1].Split(';'); InfoFarmaco nuevo = new InfoFarmaco { ID = Int32.Parse(datos[0]), Nombre = datos[1], Descripcion = datos[2], Productora = datos[3], Precio = double.Parse(datos[4]), Existencia = int.Parse(datos[5]) }; return(View("AgregarProducto", nuevo)); }
public ActionResult AgregarProducto(int id) { bool valido = true; string aux = Storage.Instance.ListadoFarmacos[id]; InfoFarmaco nuevo = new InfoFarmaco { ID = Int32.Parse(aux.Substring(0, aux.IndexOf(','))) }; aux = aux.Remove(0, aux.IndexOf(',') + 1); //Nombre if (aux.IndexOf('\"') == 0) { aux = aux.Remove(0, 1); nuevo.Nombre = aux.Substring(0, aux.IndexOf('\"')); aux = aux.Remove(0, aux.IndexOf('\"') + 2); } else { nuevo.Nombre = aux.Substring(0, aux.IndexOf(',')); aux = aux.Remove(0, aux.IndexOf(',') + 1); } for (int i = 0; i < Storage.Instance.Pedidos.Count; i++) { if (Storage.Instance.Pedidos[i].Nombre == nuevo.Nombre) { valido = false; i = Storage.Instance.Pedidos.Count; } } if (valido) { //Descripcion if (aux.IndexOf('\"') == 0) { aux = aux.Remove(0, 1); nuevo.Descripcion = aux.Substring(0, aux.IndexOf('\"')); aux = aux.Remove(0, aux.IndexOf('\"') + 2); } else { nuevo.Descripcion = aux.Substring(0, aux.IndexOf(',')); aux = aux.Remove(0, aux.IndexOf(',') + 1); } //Productora if (aux.IndexOf('\"') == 0) { aux = aux.Remove(0, 1); nuevo.Productora = aux.Substring(0, aux.IndexOf('\"')); aux = aux.Remove(0, aux.IndexOf('\"') + 3); } else { nuevo.Productora = aux.Substring(0, aux.IndexOf(',')); aux = aux.Remove(0, aux.IndexOf(',') + 2); } nuevo.Precio = double.Parse(aux.Substring(0, aux.IndexOf(','))); aux = aux.Remove(0, aux.IndexOf(',') + 1); nuevo.Existencia = Int32.Parse(aux); return(View("AgregarProducto", nuevo)); } else { return(RedirectToAction("Index")); } }