public ActionResult SectionsList()
        {
            ViewData["title"] = "Enrollment Dashboard";

            IProxy proxy = new APIProxy();

            //If the user and role aren't null
            if (Session["user"] != null && Session["role"] != null)
            {
                User currentUser = (User)Session["user"];
                //If the user is a student
                if (String.Equals("student", (string)Session["Role"], StringComparison.OrdinalIgnoreCase))
                {
                    Student student = proxy.getStudent(currentUser.ID);
                    currentSections = proxy.getStudentSections(student);
                }
                //If the user is an instructor
                else if (String.Equals("professor", (string)Session["Role"], StringComparison.OrdinalIgnoreCase))
                {
                    Instructor instructor = proxy.getInstructor(currentUser.ID);
                    currentSections = proxy.getInstructorSections(instructor);
                }
                //If the user is an admin
                else if (String.Equals("admin", (string)Session["Role"], StringComparison.OrdinalIgnoreCase))
                {
                }
            }



            return(View(currentSections));
        }
Example #2
0
        public ActionResult QOD()
        {
            APIProxy p     = new APIProxy();
            string   quote = p.getQuote();

            ViewData["Quote"] = System.Web.HttpUtility.HtmlDecode(quote.Replace("<p>", "").Replace("</p>", ""));
            return(PartialView());
        }
        public static void Main(string[] args)
        {
            const string url = "http://192.168.83.104/osticket";
            const string chave = "DCFB4EC0A3D6E6A93C92397DE72739E9";

            var ticket = new Ticket()
            {
                Name = "Nome da Pessoa",
                Email = "email",
                TopicId = (int)Categoria.Reclamacao,
                Subject = "Reclamação 2",
                Message = PrepararMensagem("Conteúdo de Reclamação 2"),
                IsMessageHtml = true
            };
            ticket.ExtraFields.Add("cpf", "Número do CPF");
            ticket.ExtraFields.Add("phone", "Número do Telefone");

            var proxy = new APIProxy(url, chave);
            int retornoEnvio = proxy.SubmitTicket(ticket);

            Console.WriteLine(retornoEnvio);
        }
Example #4
0
        public ActionResult TestApi(string function, string parameters, string proxyType)
        {
            if (Session["user"] == null)
            {
                return(RedirectToAction("Index", "Login", new { redirectAction = "TestApi", redirectController = "Home" }));
            }

            Models.Student    s  = new StudentEnrollment.Models.Student(1, "rs4296", "*****@*****.**", "Rob", "Stone", 5, float.Parse("3.5"));
            Models.Instructor i  = new StudentEnrollment.Models.Instructor(1, "gj888", "*****@*****.**", "Bob", "Smith");
            Models.Course     c1 = new StudentEnrollment.Models.Course(1, "SWEN-344", "Web Engineering", 3, 2, false);
            Models.Course     c2 = new StudentEnrollment.Models.Course(2, "CS-420", "Data Mining", 3, 3, false);
            Models.Course     c3 = new StudentEnrollment.Models.Course(3, "SWEN-261", "Intro to SE", 3, 1, false);
            Models.Course     c4 = new StudentEnrollment.Models.Course(4, "CS-262", "Engineering of Software Subsystems", 3, 1, false);
            List <StudentEnrollment.Models.Course> courses = new List <Models.Course> {
                c1, c2, c3, c4
            };

            ViewData["Function"]   = function;
            ViewData["Parameters"] = parameters;
            ViewData["ProxyType"]  = proxyType;
            IProxy p;

            if (proxyType == "Local")
            {
                p = new LocalProxy(new ServerPathData());
            }
            else
            {
                p = new APIProxy();
            }
            dynamic result = "The function returned void.";

            if (function != null)
            {
                try
                {
                    switch (function)
                    {
                    case "getStudent": result = p.getStudent(Int32.Parse(parameters)); break;

                    case "getInstructor": result = p.getInstructor(Int32.Parse(parameters)); break;

                    case "getAdmin": result = p.getAdmin(Int32.Parse(parameters)); break;

                    case "getCourse": result = p.getCourse(Int32.Parse(parameters)); break;

                    case "getCourseList": result = p.getCourseList(); break;

                    case "getSection": result = p.getSection(Int32.Parse(parameters)); break;

                    case "getCourseSections":
                        Course course = (Course)ModelFactory.createModelFromJson("course", parameters);
                        result = p.getCourseSections(course);
                        break;

                    case "getStudentSections":
                        Student student = (Student)ModelFactory.createModelFromJson("student", parameters);
                        result = p.getStudentSections(student);
                        break;

                    //result = p.getStudentSections((Student)Convert.ChangeType(parameters, typeof(Student))); break;
                    case "getSectionStudents":
                        Section section = (Section)ModelFactory.createModelFromJson("section", parameters);
                        result = p.getSectionStudents(section);
                        //result = p.getSectionStudents((Section)Convert.ChangeType(parameters, typeof(Section)));
                        break;

                    case "getInstructorSections":
                        Instructor instructor = (Instructor)ModelFactory.createModelFromJson("instructor", parameters);
                        result = p.getInstructorSections(instructor);
                        //result = p.getInstructorSections((Instructor)Convert.ChangeType(parameters, typeof(Instructor)));
                        break;

                    case "getBook": result = p.getBook(Int32.Parse(parameters)); break;

                    case "getSectionBooks":
                        section = (Section)ModelFactory.createModelFromJson("section", parameters);
                        result  = p.getSectionBooks(section);
                        //result = p.getSectionBooks((Section)Convert.ChangeType(parameters, typeof(Section)));
                        break;

                    case "getLocation": result = p.getLocation(Int32.Parse(parameters)); break;

                    case "getCurrentTerm": result = p.getCurrentTerm(); break;

                    case "getTerm": result = p.getTerm(parameters); break;

                    case "getTerms": result = p.getTerms(); break;

                    case "createTerm":
                        Term term = (Term)ModelFactory.createModelFromJson("term", parameters);
                        p.createTerm(term);
                        result = "Call the getTerms method for the result of this operation.";
                        break;

                    case "createCourse":
                        course = (Course)ModelFactory.createModelFromJson("course", parameters);
                        p.createCourse(course);
                        result = "Check the course list for the result of that operation.";
                        break;
                    }
                }
                catch (FormatException fex)
                {
                    ViewData["Result"] = "The input needs to be an integer.";
                    System.Diagnostics.Debug.WriteLine("Function: " + function + " Parameter: " + parameters + " " + fex);
                    return(View());
                }
                catch (InvalidCastException icex)
                {
                    ViewData["Result"] = "Your input was not properly formatted for that object type.";
                    System.Diagnostics.Debug.WriteLine("Function: " + function + " Parameter: " + parameters + " " + icex);
                    return(View());
                }
                catch (NotImplementedException niex)
                {
                    ViewData["Result"] = "This function is currently not implemented by this proxy.";
                    System.Diagnostics.Debug.WriteLine("Function: " + function + " Parameter: " + parameters + " " + niex);
                    return(View());
                }
                catch (Exception ex)
                {
                    ViewData["Result"] = "An unkown error occured.";
                    System.Diagnostics.Debug.WriteLine("Function: " + function + " Parameter: " + parameters + " " + ex);
                    return(View());
                }
            }
            if (result == null)
            {
                ViewData["Result"] = result;
                return(View());
            }

            // The function returned an object or a list of objects
            if (result.GetType().IsArray)
            {
                ViewData["Result"] = string.Join("\n", (object[])result);
            }
            else
            {
                var json = Newtonsoft.Json.JsonConvert.SerializeObject(result);
                ViewData["Result"] = json;
            }
            return(View());
        }
Example #5
0
 APIProxy PegarResultado(string str)
 {
     APIProxy APIRetorno = new APIProxy();
     string[] Resultados = Separar(";", str);
     APIRetorno.response_time = double.Parse(Resultados[0]);
     APIRetorno.speed = int.Parse(Resultados[1]);
     APIRetorno.Localizacao = Resultados[2];
     APIRetorno.Tipo = APIRetorno.Parse(int.Parse(Resultados[3]));
     return APIRetorno;
 }
Example #6
0
        public bool Verificar(string IP, string Port)
        {
            string Resposta = PegarAPI(IP, Port);

                APIProxy AP = new APIProxy();
                AP = PegarResultado(Resposta);
                if (AP.response_time > 0.5)
                {
                    return true;
                }

            return false;
        }
 public APIProxyTests()
 {
     this.proxy = new APIProxy();
 }