Exemplo n.º 1
0
        /// <summary>
        /// Allows create a new subject
        /// </summary>
        /// <param name="id">id subject</param>
        /// <param name="name">name subject</param>
        /// <param name="theoryH">theory hours subject</param>
        /// <param name="practiceH">practice hours subject</param>
        /// <returns></returns>
        public IActionResult Create(string name, string theoryH, string practiceH)
        {
            sbyte theoryHours   = sbyte.Parse(theoryH);
            sbyte practiceHours = sbyte.Parse(practiceH);

            //Verify if the hors are correct
            if ((theoryHours + practiceHours) < 7 && (theoryHours + practiceHours) > 0)
            {
                Subject subject = new Subject {
                    Name          = name.ToUpper(),
                    TheoryHours   = theoryHours,
                    PracticeHours = practiceHours
                };
                db.Subjects.Add(subject);
                db.SaveChanges();
                subject.GenerateKey(subject.ID);
                db.Update(subject);
                db.SaveChanges();
            }
            else
            {
                return(RedirectToAction("Subjects", new { mesage = "The hours are incorrect" }));
            }
            return(RedirectToAction("Subjects"));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create new teacher
        /// </summary>
        /// <param name="names">teacher name</param>
        /// <param name="middleName">teacher middle name</param>
        /// <param name="lastName">teacher last name</param>
        /// <param name="birthDate">teacher birthdate</param>
        /// <param name="genre">teacher genre</param>
        /// <param name="password">teacher password</param>
        /// <param name="type">if is a cordinator</param>
        /// <param name="isBase">teacher type</param>
        /// <returns></returns>
        public IActionResult Create(string names, string middleName, string lastName, string birthDate, string genre, string password, string type, string isBase)
        {
            Teacher teacher;

            //Check the teacher type
            if (type == "true")
            {
                teacher        = new Cordinator();
                teacher.IsBase = true;
            }
            else
            {
                teacher        = new Teacher();
                teacher.IsBase = Boolean.Parse(isBase);
            }
            //Put values
            teacher.Names      = names.ToUpper();
            teacher.MiddleName = middleName.ToUpper();
            teacher.LastName   = lastName.ToUpper();
            teacher.BirthDate  = DateTime.Parse(birthDate);
            teacher.Gender     = genre[0];
            teacher.Password   = Encrypt(password);
            teacher.KeysGenerator();
            db.Teachers.Add(teacher);
            db.SaveChanges();
            //Generate the roster by the teacher ID
            teacher.Roaster = (1000 + teacher.ID).ToString();
            db.Update(teacher);
            db.SaveChanges();
            return(RedirectToAction("Index", "Admin"));
        }