public SignalRConnection(Client client) { this.client = client; connection = new HubConnectionBuilder() .WithUrl(APIUrl.SignalR()) .Build(); connectionToServer(); }
public static string HttpPost(APIUrl PostType, string PostData, string Server) { string text = string.Empty; switch (Server) { case "0": text = "https://tw.bfapp.beanfun.com/"; break; case "1": text = "https://alpha-bfapp.beanfun.com/"; break; case "2": text = "http://localhost:18402/"; break; } switch (PostType) { case APIUrl.GetSk: text += "api/check/Archaeopteryx0010"; break; case APIUrl.GetRc: text += "api/check/Archaeopteryx0006"; break; case APIUrl.CreRl: text += "api/check/Archaeopteryx0007"; break; case APIUrl.CreLl: text += "api/check/Archaeopteryx0009"; break; } try { HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(text); httpWebRequest.Method = "POST"; httpWebRequest.ContentType = "application/x-www-form-urlencoded"; byte[] bytes = Encoding.ASCII.GetBytes(PostData); httpWebRequest.ContentLength = bytes.Length; using (Stream stream = httpWebRequest.GetRequestStream()) { stream.Write(bytes, 0, bytes.Length); stream.Close(); } using (HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse()) { return(new StreamReader(httpWebResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd()); } } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> Index() { var lTipo = new List <Tipo>(); var response = await HttpGeneric.Get(APIUrl.Url() + "Tipo/ListarTodos"); if (response.Code == 200) { lTipo = JsonConvert.DeserializeObject <List <Tipo> >(response.Result.ToString()); } return(View(lTipo)); }
public async Task <IActionResult> Index() { var Model = new List <FichaExercicio>(); var response = await HttpGeneric.Get(APIUrl.Url() + "FilaFicha/ListarFila"); if (response.Code == 200) { Model = JsonConvert.DeserializeObject <List <FichaExercicio> >(response.Result.ToString()); Model = Model.OrderBy(x => x.Exercicio.Descricao).ToList(); } return(View(Model)); }
public async Task <IActionResult> ControlarFicha() { var lFicha = new List <Ficha>(); var response = await HttpGeneric.Get(APIUrl.Url() + "Ficha/ListarTodos"); if (response.Code == 200) { lFicha = JsonConvert.DeserializeObject <List <Ficha> >(response.Result.ToString()); } lFicha = lFicha.OrderBy(x => x.DiaSeq).ToList(); return(View(lFicha)); }
private async Task <Tipo> BuscarTipoPorId(int IDTipo) { var Tipo = new Tipo(); var response = await HttpGeneric.Post(APIUrl.Url() + "Tipo/BuscaDinamicaRigida", BuscaDinamica.Add(new List <BuscaDinamica>(), "IDTipo", IDTipo, true)); if (response.Code == 200) { List <Tipo> lTipo = JsonConvert.DeserializeObject <List <Tipo> >(response.Result.ToString()); Tipo = lTipo.First(); } return(Tipo); }
private async Task <Ficha> BuscarFichaPorId(int IDFicha) { var Ficha = new Ficha(); var response = await HttpGeneric.Post(APIUrl.Url() + "Ficha/BuscaDinamicaRigida", BuscaDinamica.Add(new List <BuscaDinamica>(), "IDFicha", IDFicha, true)); if (response.Code == 200) { List <Ficha> lFicha = JsonConvert.DeserializeObject <List <Ficha> >(response.Result.ToString()); Ficha = lFicha.First(); } return(Ficha); }
private static async Task <List <int> > PopularDiaSeq(int IDFicha = 0) { int[] sequenciaisPossiveis = new int[] { 1, 2, 3, 4, 5 }; var lFicha = new List <Ficha>(); var response = await HttpGeneric.Get(APIUrl.Url() + "Ficha/ListarTodos"); if (response.Code == 200) { lFicha = JsonConvert.DeserializeObject <List <Ficha> >(response.Result.ToString()); } return(sequenciaisPossiveis.Except(lFicha.Where(x => x.IDFicha != IDFicha).Select(x => x.DiaSeq).ToList()).ToList()); }
public async Task <IActionResult> Cadastrar() { Exercicio Exercicio = new Exercicio(); Exercicio.Tipos = new List <Tipo>(); var response = await HttpGeneric.Post(APIUrl.Url() + "Tipo/BuscaDinamicaRigida", BuscaDinamica.Add(new List <BuscaDinamica>(), "Status", 1, true)); if (response.Code == 200) { Exercicio.Tipos = JsonConvert.DeserializeObject <List <Tipo> >(response.Result.ToString()); } return(View(Exercicio)); }
public ActionResult Index() { using (var client = new WebClient()) { try { var obj = client.DownloadString(APIUrl.Tarefas(Convert.ToInt32(User.Identity.Name))); var tarefas = JsonConvert.DeserializeObject(obj, typeof(List <Interface.Tarefa>)); var viewModel = Mapper.Map <List <TarefaViewModel> >(tarefas); return(View(viewModel)); } catch (WebException ex) { ModelState.AddModelError(string.Empty, ex.Message); return(View()); } } }
public async Task <IActionResult> VincularExercicio(int IDFicha) { var Model = new FichaExercicio(); Model.Ficha = BuscarFichaPorId(IDFicha).Result; Model.IDFicha = Model.Ficha.IDFicha; Model.Exercicios = new List <Exercicio>(); var response = await HttpGeneric.Get(APIUrl.Url() + "Exercicio/ListarTodos"); if (response.Code == 200) { Model.Exercicios = JsonConvert.DeserializeObject <List <Exercicio> >(response.Result.ToString()); } return(View(Model)); }
public ActionResult NovaTarefa() { using (var client = new WebClient()) { try { var obj = client.DownloadString(APIUrl.QuestoesPorProfessor(Convert.ToInt32(User.Identity.Name))); var questoes = JsonConvert.DeserializeObject(obj, typeof(List <Interface.Questao>)); var viewModel = Mapper.Map <TarefaViewModel>(questoes); return(View(viewModel)); } catch (WebException ex) { ModelState.AddModelError(string.Empty, ex.Message); return(View()); } } }
public ActionResult EnviarTarefaATurma(TarefaViewModel viewModel) { var tarefaMapeada = Mapper.Map <TarefaTurma>(viewModel); using (var client = new WebClient()) { client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); try { client.UploadString(APIUrl.EnviarTarefaTurma(), "POST", JsonConvert.SerializeObject(tarefaMapeada)); } catch (WebException ex) { ModelState.AddModelError(string.Empty, ex.Message); } } return(RedirectToAction("Index")); }
public async Task <IActionResult> CadastrarFichaExercicio(FichaExercicio FichaExercicio) { var response = await HttpGeneric.Post(APIUrl.Url() + "FichaExercicio/Criar", FichaExercicio); if (response.Code == 200) { TempData["Sucesso"] = response.Result; return(RedirectToAction("FichaExercicio", "Ficha", new { IDFicha = FichaExercicio.IDFicha })); } else { TempData["Erro"] = response.Result; return(View(FichaExercicio)); } }
public async Task <IActionResult> Editar(Tipo Tipo) { var response = await HttpGeneric.Put(APIUrl.Url() + "Tipo/Alterar", Tipo); if (response.Code == 200) { TempData["Sucesso"] = response.Result; return(RedirectToAction("Index", "Tipo")); } else { TempData["Erro"] = response.Result; return(View(Tipo)); } }
public async Task <IActionResult> EditarFicha(Ficha Ficha) { var response = await HttpGeneric.Put(APIUrl.Url() + "Ficha/Alterar", Ficha); if (response.Code == 200) { TempData["Sucesso"] = response.Result; return(RedirectToAction("ControlarFicha", "Ficha")); } else { TempData["Erro"] = response.Result; return(View(Ficha)); } }
public async Task <IActionResult> Cadastrar(Tipo Tipo) { Tipo.Status = 1; var response = await HttpGeneric.Post(APIUrl.Url() + "Tipo/Criar", Tipo); if (response.Code == 200) { TempData["Sucesso"] = response.Result; return(RedirectToAction("Index", "Tipo")); } else { TempData["Erro"] = response.Result; return(View(Tipo)); } }
public ActionResult ResolverTarefa(int idTarefa) { using (var client = new WebClient()) { try { var obj = client.DownloadString(APIUrl.TarefaPorId(idTarefa, Convert.ToInt32(User.Identity.Name))); var resolucoes = JsonConvert.DeserializeObject(obj, typeof(Interface.Resolucao)); var viewModel = Mapper.Map <ResolucaoViewModel>(resolucoes); return(View(viewModel)); } catch (WebException ex) { ModelState.AddModelError(string.Empty, ex.Message); return(View()); } } }
public ActionResult Index(string login) { var webClient = new WebClient(); Stream stream = null; try { stream = webClient.OpenRead(APIUrl.Login(login)); } catch (WebException ex) { if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.NotFound) { ModelState.AddModelError(string.Empty, "Usário não encontrado."); return(View()); } if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.BadRequest) { ModelState.AddModelError(string.Empty, "Informe um login."); return(View()); } } var retorno = new StreamReader(stream).ReadToEnd(); var obj = JObject.Parse(retorno); var usuario = Helpers.ToUsuario(obj); FormsAuthentication.SetAuthCookie(usuario.Id, false); var authTicket = new FormsAuthenticationTicket(1, usuario.Id, DateTime.Now, DateTime.Now.AddMinutes(20), false, usuario.Tipo); string encryptedTicket = FormsAuthentication.Encrypt(authTicket); var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); Response.Cookies.Add(authCookie); var infoCookie = new HttpCookie("infoCookie", usuario.Nome); Response.Cookies.Add(infoCookie); if (usuario.Tipo == "Professor") { return(RedirectToAction("Index", "Professor")); } return(RedirectToAction("Index", "Aluno")); }
public ActionResult NovaQuestao(QuestaoViewModel viewModel) { var questao = Mapper.Map <Interface.Questao>(viewModel); questao.IdProfessor = Convert.ToInt32(User.Identity.Name); using (var client = new WebClient()) { client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); try { client.UploadString(APIUrl.SalvarQuestao(), "POST", JsonConvert.SerializeObject(questao)); } catch (WebException ex) { ModelState.AddModelError(string.Empty, ex.Message); } } return(RedirectToAction("NovaQuestao")); }
public async Task <IActionResult> CadastrarFicha(Ficha Ficha) { Ficha.DataCriacao = DateTime.Now; Ficha.Status = 1; var response = await HttpGeneric.Post(APIUrl.Url() + "Ficha/Criar", Ficha); if (response.Code == 200) { TempData["Sucesso"] = response.Result; return(RedirectToAction("ControlarFicha", "Ficha")); } else { TempData["Erro"] = response.Result; return(View(Ficha)); } }
public async Task <IActionResult> FichaExercicio(int IDFicha) { var Model = new FichaExercicioVM(); Model.Ficha = BuscarFichaPorId(IDFicha).Result; Model.FichaExercicio = new List <FichaExercicio>(); var lModel = new List <Ficha>(); var response = await HttpGeneric.Post(APIUrl.Url() + "FichaExercicio/BuscaDinamicaRigida", BuscaDinamica.Add(new List <BuscaDinamica>(), "IDFicha", IDFicha, true)); if (response.Code == 200) { Model.FichaExercicio = JsonConvert.DeserializeObject <List <FichaExercicio> >(response.Result.ToString()); Model.FichaExercicio = Model.FichaExercicio.OrderBy(x => x.Exercicio.Descricao).ToList(); } Model.FichaExercicio = Model.FichaExercicio.OrderBy(x => x.Exercicio.Descricao).ToList(); return(View(Model)); }
public ActionResult Abrirresolucao(ResolucaoViewModel viewModel) { var resolucao = Mapper.Map <Resolucao>(viewModel); resolucao.IdAluno = viewModel.Questoes[0].IdAluno; using (var client = new WebClient()) { client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); try { client.UploadString(APIUrl.ResolucaoQuestaoSalvarResolucaoAluno(), "PUT", JsonConvert.SerializeObject(resolucao)); return(RedirectToAction("Index")); } catch (WebException ex) { ModelState.AddModelError(string.Empty, ex.Message); return(RedirectToAction("Index")); } } }
public ActionResult EnviarParaCorrecao(int idResolucao) { var resolucao = new Resolucao { Id = idResolucao, IdAluno = Convert.ToInt32(User.Identity.Name) }; using (var client = new WebClient()) { client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); try { client.UploadString(APIUrl.EnviarTarefaParaCorrecao(), "PUT", JsonConvert.SerializeObject(resolucao)); return(RedirectToAction("Index")); } catch (WebException ex) { ModelState.AddModelError(string.Empty, ex.Message); return(RedirectToAction("Index")); } } }
public async Task <IActionResult> AlterarSituacao(int IDFicha) { var Ficha = BuscarFichaPorId(IDFicha).Result; if (Ficha != null) { if (Ficha.Status == 1) { Ficha.Status = 0; } else { Ficha.Status = 1; } var response = await HttpGeneric.Put(APIUrl.Url() + "Ficha/Alterar", Ficha); if (response.Code == 200) { if (Ficha.Status == 1) { TempData["Sucesso"] = "Ficha foi ativada com sucesso!"; } else { TempData["Sucesso"] = "Ficha foi desativada com sucesso!"; } return(RedirectToAction("ControlarFicha", "Ficha")); } else { TempData["Erro"] = response.Result; return(View(Ficha)); } } else { TempData["Erro"] = "Ficha não encontrado para alteração!"; return(View(Ficha)); } }
public async Task <IActionResult> AlterarSituacao(int IDTipo) { var Tipo = BuscarTipoPorId(IDTipo).Result; if (Tipo != null) { if (Tipo.Status == 1) { Tipo.Status = 0; } else { Tipo.Status = 1; } var response = await HttpGeneric.Put(APIUrl.Url() + "Tipo/Alterar", Tipo); if (response.Code == 200) { if (Tipo.Status == 1) { TempData["Sucesso"] = "Tipo foi ativado com sucesso!"; } else { TempData["Sucesso"] = "Tipo foi desativado com sucesso!"; } return(RedirectToAction("Index", "Tipo")); } else { TempData["Erro"] = response.Result; return(View(Tipo)); } } else { TempData["Erro"] = "Tipo não encontrado para alteração!"; return(View(Tipo)); } }
public ActionResult ObterAlunos(TarefaViewModel viewModel) { using (var client = new WebClient()) { try { var obj = client.DownloadString(APIUrl.TurmaObterAlunos(viewModel.TurmaEscolhida, viewModel.Id)); var alunos = JsonConvert.DeserializeObject(obj, typeof(List <Interface.AlunoTarefa>)); var listaAlunoViewModel = Mapper.Map <List <AlunoTarefaViewModel> >(alunos); foreach (var lista in listaAlunoViewModel) { lista.IdTarefa = viewModel.Id; } return(PartialView("_ListaAlunos", listaAlunoViewModel)); } catch (WebException ex) { ModelState.AddModelError(string.Empty, ex.Message); return(null); } } }
/// <summary> /// Returns the DomainSettings Object /// </summary> /// <param name="domainName">DomainName to be interogated.</param> /// <returns></returns> private async Task <DomainSetting> GetDomainSettingsAsync(string domainName) { //Sanitize API URL var _providerEndpoint = APIUrl.Replace('"', ' '); _providerEndpoint = _providerEndpoint.Trim(); if (!_providerEndpoint.Contains("https")) { _providerEndpoint = "https://" + _providerEndpoint; } var client = new RestClient(_providerEndpoint); var request = new RestRequest("/v2/" + domainName + "/settings", Method.GET); var response = new RestResponse(); response = await GetResponseContentAsync(client, request) as RestResponse; return(JsonConvert.DeserializeObject <DomainSetting>(response.Content)); }
public ActionResult ResolverTarefa(ResolucaoViewModel viewModel) { var resolucao = Mapper.Map <Resolucao>(viewModel); foreach (var questao in resolucao.Questoes) { questao.IdAluno = Convert.ToInt32(User.Identity.Name); } using (var client = new WebClient()) { client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); try { client.UploadString(APIUrl.SalvarRespostasDeTarefa(), "POST", JsonConvert.SerializeObject(resolucao)); return(RedirectToAction("Index")); } catch (WebException ex) { ModelState.AddModelError(string.Empty, ex.Message); return(RedirectToAction("ResolverTarefa", new { IdTarefa = viewModel.IdTarefa })); } } }
public ActionResult VerCorrecao(int idAluno, int idTarefa) { using (var client = new WebClient()) { try { var obj = client.DownloadString(APIUrl.ResolucaoQuestaoObterResolucaoAluno(idAluno, idTarefa)); var resolucoes = JsonConvert.DeserializeObject(obj, typeof(Interface.Resolucao)); var viewModel = Mapper.Map <ResolucaoViewModel>(resolucoes); viewModel.IdTarefa = idTarefa; foreach (var questao in viewModel.Questoes) { questao.IdAluno = idAluno; } return(View(viewModel)); } catch (WebException ex) { ModelState.AddModelError(string.Empty, ex.Message); return(View()); } } }