/// <summary>
        /// Stores all Symbols in ViewData["symbols"],
        /// all symbols with symboltype other than normal in ViewDate["types"],
        /// and all CompositeSymbols in ViewData["comp"], 
        /// and returns the index-view of WriteController.
        /// </summary>
        /// <returns>~/Write/Inex.cshtml</returns>
        public ActionResult Index()
        {
            SymbolBLL symbols = new SymbolBLL();
            ViewData["symbols"] = symbols.GetAllSymbols();

            SymbolTypeBLL types = new SymbolTypeBLL();
            ViewData["types"] = types.GetAllNonStandard();

            CompositeSymbolBLL comp = new CompositeSymbolBLL();
            ViewData["comp"] = comp.GetAll();

            CompositeOfBLL compOf = new CompositeOfBLL();
            ViewData["compOf"] = compOf.getAllRelations();

            return View();
        }
        /// <summary>
        /// Gets the id of the CompositeSymbol you want to edit, 
        /// the symbols it is made of, and a list of all Symbols,
        /// saves them in ViewData and then returns the Edit-view.
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Edit-view</returns>
        public ActionResult Edit(int id)
        {
            if (Session["logged_in"] == null)
                return RedirectToAction("Index", "Index");

            CompositeSymbolBLL comp = new CompositeSymbolBLL();
            CompositeSymbol find = comp.GetExaxtComositeSymbolByID(id);

            CompositeOfBLL compOf = new CompositeOfBLL();

            SymbolBLL symb = new SymbolBLL();

            List<Symbol> symbols = compOf.GetComponentsOf(find);

            SymbolTypeBLL types = new SymbolTypeBLL();

            ViewData["comp"] = find;
            ViewData["symbList"] = symbols;
            ViewData["otherSymbols"] = symb.GetAllSymbols();
            ViewData["Types"] = types.GetAllNonStandard();
            return View();
        }
        public ActionResult Suggestions(SuggestionsModel myModel)
        {
            var symbolId = myModel.symbolId;
            var currentSuggestions = myModel.currentSuggestions;
            var first = myModel.first;

            System.Diagnostics.Debug.WriteLine(first + " AND ID IS " + symbolId + " SIR");
            var listOfComp = new List<CompositeSymbol>();
            if(first == "true")
            {
                CompositeSymbolBLL comp = new CompositeSymbolBLL();
                listOfComp = comp.GetAll();
                System.Diagnostics.Debug.WriteLine("FILLED LIST WITH ALL COMP SYMBOLS FROM BLL SIR");
            }
            else
            {
                foreach(CompositeSymbol co in currentSuggestions)
                {
                    CompositeSymbolBLL comp = new CompositeSymbolBLL();
                    listOfComp.Add(comp.GetExaxtComositeSymbolByID(co.compId));
                }
                //listOfComp = currentSuggestions;
                System.Diagnostics.Debug.WriteLine("NUMBER IS: " + currentSuggestions.Count + ", FILLING LIST WITH LIST IN PARAMETER SIR");
            }

            if(listOfComp.Count == 0)
            {
                System.Diagnostics.Debug.WriteLine("VERY EMPTY THIS LIST SIR");
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("LIST HAS VALUES SIR");
            }

            CompositeOfBLL compOf = new CompositeOfBLL();
            CompositeScoreBLL score = new CompositeScoreBLL();
            List<CompositeSymbol> suggestions = new List<CompositeSymbol>();

            var lastScore = 0;
            foreach(CompositeSymbol c in listOfComp)
            {
                if (c != null)
                    System.Diagnostics.Debug.WriteLine("COMP SYMBOL DOES EXCIST SIR");
                else
                    System.Diagnostics.Debug.WriteLine("COMP SYMBOL DOES NOT EXIST SIR");

                var temp = compOf.GetComponentsOf(c);
                foreach(Symbol s in temp)
                {
                    if(s.symId == symbolId)
                    {
                        if(score.GetScoreFor(c.compId) >= lastScore)
                        {
                            suggestions.Insert(0, c);
                            lastScore = score.GetScoreFor(c.compId);
                        }
                        else
                            suggestions.Add(c);
                    }
                }
            }

            return Json(suggestions);
        }
        public ActionResult Edit(Int32[] isPartOf, int compId)
        {
            if (Session["logged_in"] == null)
                return RedirectToAction("Index", "Index");

            CompositeSymbolBLL comp = new CompositeSymbolBLL();
            SymbolBLL symbols = new SymbolBLL();

            CompositeSymbol editedComp = comp.GetExaxtComositeSymbolByID(compId);
            List<Symbol> partOf = new List<Symbol>();

            foreach(Int32 part in isPartOf)
            {
                var temp = symbols.GetExactByID(part);
                if(temp != null)
                {
                    partOf.Add(temp);
                }
            }

            CompositeOfBLL compOf = new CompositeOfBLL();
            var ok = compOf.DeleteByCompositeSymbol(editedComp);
            if(ok)
            {
                ok = compOf.SetCompositeOfSymbol(editedComp, partOf);
                if(ok)
                {
                    TempData["msg"] = "Composite Symbol '" + editedComp.compName + "' was successfully edited.";
                }
                else
                {
                    TempData["msg"] = "Error when editing.";
                }
            }
            return RedirectToAction("Index");
        }