public bool AddRequiredCourses(CurricularUnitForm unit)
 {
     if (_requiredCourses.Contains(unit))
         return false;
     _requiredCourses.Add(unit);
     return true;
 }
        public static CurricularUnitForm Process(IEnumerable<KeyValuePair<string, string>> content)
        {
            if (content == null) return null;

            CurricularUnitForm cuf = new CurricularUnitForm();

            cuf.CUnit.Acronym = content.Where(p => p.Key == "acronym").FirstOrDefault().Value;
            cuf.CUnit.Name = content.Where(p => p.Key == "name").FirstOrDefault().Value;
            cuf.CUnit.ECTS = Double.Parse(content.Where(p => p.Key == "credits").FirstOrDefault().Value);

            cuf.Type.CourseType = (CourseType)Enum.Parse(typeof(CourseType), content.Where(p => p.Key == "coursetype").FirstOrDefault().Value);
            cuf.Type.Degree = (Degree)Enum.Parse(typeof(Degree), content.Where(p => p.Key == "degree").FirstOrDefault().Value);
            cuf.Type.Semester = (Semester)Enum.Parse(typeof(Semester), content.Where(p => p.Key == "semester").FirstOrDefault().Value);

            cuf.Description.CourseProgram = content.Where(p => p.Key == "courseprogram").FirstOrDefault().Value;
            cuf.Description.Language = "PT";
            cuf.Description.LearningResults = content.Where(p => p.Key == "learningresults").FirstOrDefault().Value;
            cuf.Description.Objectives = content.Where(p => p.Key == "objectives").FirstOrDefault().Value;
            cuf.Description.ResultEvaluation = content.Where(p => p.Key == "resultevaluation").FirstOrDefault().Value;

            //TODO Required Courses
            //TODO Verify Contents

            return cuf;
        }
        public static XmlDocument Write(CurricularUnitForm cuf, bool declaration)
        {
            XmlDocument xmlFile = new XmlDocument();
            if (declaration)
                xmlFile.AppendChild(xmlFile.CreateXmlDeclaration("1.0","utf-8", null));

            XmlElement fuc = xmlFile.CreateElement("fuc");
            fuc.SetAttribute("id",cuf.ID.ToString());
            xmlFile.AppendChild(fuc);

            XmlElement uc = xmlFile.CreateElement("uc");
            uc.SetAttribute("name", cuf.CUnit.Name);
            uc.SetAttribute("acronym", cuf.CUnit.Acronym);
            uc.SetAttribute("ects", cuf.CUnit.ECTS.ToString());
            fuc.AppendChild(uc);

            XmlElement req = xmlFile.CreateElement("required-uc");
            foreach (CurricularUnitForm requiredUC in cuf.RequiredCourses)
            {
                XmlElement reqUC = xmlFile.CreateElement("ruc");
                reqUC.SetAttribute("name", requiredUC.CUnit.Name);
                reqUC.SetAttribute("acronym", requiredUC.CUnit.Acronym);
                req.AppendChild(reqUC);
            }
            uc.AppendChild(req);

            XmlElement type = xmlFile.CreateElement("type-uc");
            type.SetAttribute("courseType", cuf.Type.CourseType.ToString());
            type.SetAttribute("semester", cuf.Type.Semester.ToString());
            type.SetAttribute("degree", cuf.Type.Degree.ToString());
            uc.AppendChild(type);

            XmlElement desc = xmlFile.CreateElement("description-uc");

            XmlElement objectives = xmlFile.CreateElement("objectives");
            objectives.InnerText = cuf.Description.Objectives;
            desc.AppendChild(objectives);

            XmlElement learningResults = xmlFile.CreateElement("learningResults");
            learningResults.InnerText = cuf.Description.LearningResults;
            desc.AppendChild(learningResults);

            XmlElement resultEvaluation = xmlFile.CreateElement("resultEvaluation");
            resultEvaluation.InnerText = cuf.Description.ResultEvaluation;
            desc.AppendChild(resultEvaluation);

            XmlElement courseProgram = xmlFile.CreateElement("courseProgram");
            courseProgram.InnerText = cuf.Description.CourseProgram;
            desc.AppendChild(courseProgram);

            XmlElement language = xmlFile.CreateElement("language");
            language.InnerText = cuf.Description.Language;
            desc.AppendChild(language);

            fuc.AppendChild(desc);
            return xmlFile;
        }
        public static bool Load(ICurricularUnitFormRepository<CurricularUnitForm> _repo, String _filePath)
        {
            try
            {
                CurricularUnitForm cuf = new CurricularUnitForm();

                if (_repo == null || _filePath == null) return false;

                XmlTextReader xmlFile = new XmlTextReader(_filePath);
                //xmlFile.Read();

                while (xmlFile.Read())
                {
                    xmlFile.MoveToElement();
                    if (xmlFile.NodeType == XmlNodeType.Element && xmlFile.Name.Equals("fuc"))
                    {
                        ulong id = ulong.Parse(xmlFile.GetAttribute("id"));

                        XmlReader xmlTree = xmlFile.ReadSubtree();
                        while (xmlTree.Read())
                        {
                            if (xmlFile.NodeType == XmlNodeType.Element)
                            {
                                switch (xmlTree.Name)
                                {
                                    case "uc":
                                        String acr = xmlFile.GetAttribute("acronym");
                                        cuf = _repo.GetByAcronym(acr);
                                        if (cuf == null)
                                            cuf = new CurricularUnitForm(xmlFile.GetAttribute("name"), acr);
                                        cuf.CUnit.Name = xmlFile.GetAttribute("name");
                                        cuf.ID = id;
                                        try
                                        {
                                            cuf.CUnit.ECTS = Convert.ToDouble(xmlFile.GetAttribute("ects"));
                                        }
                                        catch (FormatException e)
                                        {
                                            cuf.CUnit.ECTS = 0;
                                        }
                                        break;
                                    case "ruc":
                                        acr = xmlFile.GetAttribute("acronym");
                                        CurricularUnitForm cuf_aux = _repo.GetByAcronym(acr);
                                        if (cuf_aux == null)
                                            cuf_aux = new CurricularUnitForm(xmlFile.GetAttribute("name"), acr);
                                        _repo.Add(cuf_aux);
                                        cuf.AddRequiredCourses(cuf_aux);
                                        break;
                                    case "type-uc":
                                        cuf.Type.CourseType = (CourseType)Enum.Parse(typeof(CourseType), xmlFile.GetAttribute("courseType"));
                                        cuf.Type.Semester = (Semester)Enum.Parse(typeof(Semester), xmlFile.GetAttribute("semester"));
                                        cuf.Type.Degree = (Degree)Enum.Parse(typeof(Degree), xmlFile.GetAttribute("degree"));
                                        break;
                                    case "objectives":
                                        cuf.Description.Objectives = xmlFile.ReadString();
                                        break;
                                    case "learningResults":
                                        cuf.Description.LearningResults = xmlFile.ReadString();
                                        break;
                                    case "resultEvaluation":
                                        cuf.Description.ResultEvaluation = xmlFile.ReadString();
                                        break;
                                    case "courseProgram":
                                        cuf.Description.CourseProgram = xmlFile.ReadString();
                                        break;
                                    case "language":
                                        cuf.Description.Language = xmlFile.ReadString();
                                        break;
                                }
                            }
                        }
                        if (cuf.Type.Degree.Equals(Degree.EIC))
                            _repo.Add(cuf);
                    }
                }
            }

            catch (Exception e)
            {
                Console.WriteLine(e);
                return false;
            }
            return true;
        }
 public OfficialCurricularUnitForm(CurricularUnitForm t)
     : base()
 {
     CourseFile = t;
     _myType = "OFFICIAL";
 }
 public bool RemoveRequiredCourses(CurricularUnitForm unit)
 {
     if (!_requiredCourses.Contains(unit))
         return false;
     _requiredCourses.Remove(unit);
     return true;
 }
 public ProposalCurricularUnitForm(CurricularUnitForm t)
     : base()
 {
     CourseFile = t;
     _myType = "PROPOSAL";
 }