Ejemplo n.º 1
0
        public IHttpActionResult PostCalificaion(StudentCourseDTO calification)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var remoteServer = (ICourseLogic)Activator.GetObject(
                typeof(ICourseLogic),
                RemoteAddress);

            try
            {
                string response = remoteServer.AddCalificationRemoting(calification.CourseName, calification.StudentId, calification.Calification);
                if (response.Equals("OK"))
                {
                    Logs.SendTimestamp("AddCalification", "admin", "Calification added: " + calification.Calification);
                    return(Ok(response));
                }
                else
                {
                    return(BadRequest(response));
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
        public IHttpActionResult PostTeacher(TeacherDTO teacherDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            Teacher teacher = new Teacher()
            {
                Name     = teacherDTO.Name,
                LastName = teacherDTO.LastName,
                Email    = teacherDTO.Email,
                Password = teacherDTO.Password,
                Id       = Guid.NewGuid(),
            };

            db.Teachers.Add(teacher);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException e)
            {
                if (TeacherExists(teacher.Id))
                {
                    return(Conflict());
                }
                else
                {
                    BadRequest("Some error in data base " + e.Message);
                }
            }
            Logs.SendTimestamp("CreateTeacher", "admin", "Teacher added: " + teacherDTO.Name);
            return(Ok("Teacher created succesfully"));
        }
Ejemplo n.º 3
0
        private static void CreateStudent()
        {
            Console.WriteLine("*********  Create student  *********");
            int    studentId    = UI.Menu.ReadNumber("Student Id: ");
            string studentEmail = UI.Menu.ReadEmail();

            try
            {
                studentLogic.AddStudent(studentId, studentEmail);
                logs.SendTimestamp("CreateStudent", "admin", "Student registered: " + studentId);
                Console.WriteLine("Student created correctly");
            }
            catch (StudentException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("Try again please.");
                CreateStudent();
            }
        }
        private void HandleInscription()
        {
            string data       = Encoding.ASCII.GetString(Protocol.ReceiveData(ClientSocket));
            var    arrayData  = data.Split('#');
            int    studentId  = Int32.Parse(arrayData[0]);
            string courseName = arrayData[1];

            try
            {
                courseLogic.AddStudent(studentId, courseName);
                Protocol.Send(ClientSocket, "RES", CommandUtils.SUCCESS_MESSAGE, Encoding.ASCII.GetBytes("Inscription created successfully."));
                Logs.SendTimestamp("Inscription", studentId.ToString(), "Inscripction to course: " + courseName);
            }
            catch (StudentException e)
            {
                Protocol.Send(ClientSocket, "RES", CommandUtils.ERROR, Encoding.ASCII.GetBytes(e.Message));
            }
            catch (CourseException e)
            {
                Protocol.Send(ClientSocket, "RES", CommandUtils.ERROR, Encoding.ASCII.GetBytes(e.Message));
            }
        }