/* Update which concept is currently chosen and update texts
     * Will be run when value of dropdown is changed */
    public void decideCurrConcept()
    {
        currentChosenOption = dropDown.GetComponent <TMP_Dropdown>().value;
        switch (currentChosenOption)
        {
        case 0:
            currConcept = variable;
            break;

        case 1:
            currConcept = condition;
            break;

        case 2:
            currConcept = forloops;
            break;

        case 3:
            currConcept = whileloops;
            break;
            //case 4:
            //    currConcept = final;
            //    break;
        }
        updateTexts();
    }
        /// <summary>
        ///     Mapea un modelo de vista
        ///     a una entidad
        /// </summary>
        public concept ViewModelToEntity(ConceptViewModel model)
        {
            concept result = new concept();

            result.ConceptId = model.ConceptId;
            result.Nombre    = model.Nombre;
            result.RegStatus = model.RegStatus;
            result.CreatedAt = Convert.ToDateTime(model.CreatedAt);
            result.UpdatedAt = Convert.ToDateTime(model.UpdatedAt);

            return(result);
        }
        /// <summary>
        ///     mapea un objeto entidad
        ///     a un modelo de vista
        /// </summary>
        public ConceptViewModel EntityToViewModel(concept entity)
        {
            var model = new ConceptViewModel();

            model.ConceptId = entity.ConceptId;
            model.Nombre    = entity.Nombre;
            model.RegStatus = entity.RegStatus;
            model.CreatedAt = entity.CreatedAt.ToString("dd/MM/yyyy");
            model.UpdatedAt = entity.UpdatedAt.ToString("dd/MM/yyyy");

            return(model);
        }
    /* Start is called before the first frame update. Define all concepts */
    void Start()
    {
        //Which dropdown option are we looking at?
        currentChosenOption = dropDown.GetComponent <TMP_Dropdown>().value;

        /* Text for variables */
        variable = new concept();
        variable.setTitle("Variables");
        variable.setDef("A Variable is a quantity that has been assigned a special value by the programmer.\n" +
                        " It is like a box holding a value, in the sense that you can use the box instead of using the value directly!");
        variable.setExample("For Example: x = 10 implies 2 + x = 12 \n" +
                            "We can substitute 10 by x anywhere necessary. This provides a nice and neat way to modify our programs.");

        /*Text for Conditions */
        condition = new concept();
        condition.setTitle("Conditional Statements");
        condition.setDef("Conditional statements control the flow of the program and allow it to behave appropriately under different circumstances.\n" +
                         "They include 'if statements' which can be followed by 'else if' and 'else' statements which execute appropriate behaviours accordingly.");
        condition.setExample("For example \n" +
                             "'if(x){do y}\n" +
                             "else{do z}'\n" +
                             "will execute y given x is true and execute z otherwise.");

        /*Text for For Loops*/
        forloops = new concept();
        forloops.setTitle("For Loops");
        forloops.setDef("For Loops help programmers execute chunks of code in multiple interations without having to repeat the code! They are \n" +
                        "a very powerful tool that helps programmers iterate over data structures like arrays, and execute shared pieces of code among \n" +
                        "say, the different indices of the array, or even multiple arrays!");
        forloops.setExample("For loops have syntax like\n " +
                            "for (int i = 0; i< value; i++){some code}\n" +
                            " to signify that the code is meant to iterate value times, with each iteration differing by 1.");

        /*Text for While Loops*/
        whileloops = new concept();
        whileloops.setTitle("While Loops");
        whileloops.setDef("While loops help programmers execute chunks of code, guided by a condition. While the condition is true, the code \n" +
                          "keeps executing. When the condition falsifies, the while loop stops execution.\n");
        whileloops.setExample("The syntax for a while loop is the following: \n" +
                              "while(i < value){some code}.\n" +
                              "The 'some code' contains ways for iteration.");

        /*Text for the final race*/
        //final = new concept();
        //final.setTitle("The final race!");
        //final.setDef("This is the final chapter of this race! This covers all the chapters we have learned so far. Be prepared for the following:");
        //final.setExample("VARIABLES, \n IF CONDITIONS, \n WHILE LOOPS, \n FOR LOOPS");

        decideCurrConcept();
        updateTexts();
    }
        /// <summary>
        ///    Actualiza un concepto
        /// </summary>
        public concept Update(concept concepto)
        {
            concept conceptEntity = DataBaseEntities.concept.Where(w => w.ConceptId == concepto.ConceptId).FirstOrDefault();

            if (conceptEntity != null)
            {
                conceptEntity.Nombre = concepto.Nombre;

                var update = DataBaseEntities.Entry(conceptEntity);
                update.State = EntityState.Modified;
                DataBaseEntities.SaveChanges();
            }

            return(conceptEntity);
        }
        /// <summary>
        ///    Elimina un concepto
        /// </summary>
        public concept Delete(int conceptId)
        {
            concept conceptEntity = DataBaseEntities.concept.Where(w => w.ConceptId == conceptId).FirstOrDefault();

            if (conceptEntity != null)
            {
                conceptEntity.RegStatus = false;

                var update = DataBaseEntities.Entry(conceptEntity);
                update.State = EntityState.Modified;
                DataBaseEntities.SaveChanges();
            }

            return(conceptEntity);
        }
        /// <summary>
        ///      Registra un nuevo concepto
        /// </summary>
        public concept Register(concept concept)
        {
            DateTime dateTime = DateTime.Now;

            try
            {
                concept.CreatedAt = dateTime;
                concept.RegStatus = true;

                DataBaseEntities.concept.Add(concept);
                DataBaseEntities.SaveChanges();
                DataBaseEntities.Entry(concept).GetDatabaseValues();

                return(concept);
            }
            catch (Exception dbEx)
            {
                return(null);
            }
        }