Ejemplo n.º 1
0
 public PresenceHandler(JsonInformations informations)
 {
     this.Informations = informations;
     database          = Singleton <DatabaseHandler> .Instance();
 }
Ejemplo n.º 2
0
        public string ValidatePresence([FromBody] JsonInformations informations)
        {
            ResponseInfo response = new ResponseInfo();

            if (informations != null)
            {
                PresenceHandler presence                     = new PresenceHandler(informations);
                List <string>   presenceInformations         = null;
                List <Tuple <string, object> > logParameters = new List <Tuple <string, object> >();
                try {
                    presenceInformations = presence.ValidatePresence();
                    if (presenceInformations != null)
                    {
                        response = new ResponseInfo {
                            header  = "Sucesso",
                            message = presenceInformations[0] + " sua presença na aula " + presenceInformations[1] + " validada com sucesso"
                        };

                        logParameters.Add(new Tuple <string, object>("@Latitude", informations.Latitude));
                        logParameters.Add(new Tuple <string, object>("@Longitude", informations.Longitude));
                        logParameters.Add(new Tuple <string, object>("@Sucess", "Y"));
                        logParameters.Add(new Tuple <string, object>("@Error", ""));
                        presence.InsertLog(logParameters);
                        logParameters.Clear();
                        return(JsonConvert.SerializeObject(response));
                    }
                    else
                    {
                        response = new ResponseInfo {
                            header  = "Erro",
                            message = "Não foi possível validar sua presença"
                        };

                        logParameters.Add(new Tuple <string, object>("@Latitude", informations.Latitude));
                        logParameters.Add(new Tuple <string, object>("@Longitude", informations.Longitude));
                        logParameters.Add(new Tuple <string, object>("@Sucess", "N"));
                        logParameters.Add(new Tuple <string, object>("@Error", "Não foi possível validar sua presença"));
                        presence.InsertLog(logParameters);
                        logParameters.Clear();
                        return(JsonConvert.SerializeObject(response));
                    }
                } catch (ResponseException e) {
                    logParameters.Add(new Tuple <string, object>("@Latitude", informations.Latitude));
                    logParameters.Add(new Tuple <string, object>("@Longitude", informations.Longitude));
                    logParameters.Add(new Tuple <string, object>("@Sucess", "N"));
                    logParameters.Add(new Tuple <string, object>("@Error", e.Info.message));
                    presence.InsertLog(logParameters);
                    logParameters.Clear();
                    return(JsonConvert.SerializeObject(e.Info));
                } catch {
                    response = new ResponseInfo {
                        header  = "Erro",
                        message = "Ocorreu um erro interno, favor entrar em contato com o suporte"
                    };

                    logParameters.Add(new Tuple <string, object>("@Latitude", informations.Latitude));
                    logParameters.Add(new Tuple <string, object>("@Longitude", informations.Longitude));
                    logParameters.Add(new Tuple <string, object>("@Sucess", "N"));
                    logParameters.Add(new Tuple <string, object>("@Error", "Ocorreu um erro interno, favor entrar em contato com o suporte"));
                    presence.InsertLog(logParameters);
                    logParameters.Clear();
                    return(JsonConvert.SerializeObject(response));
                }
            }
            else
            {
                response = new ResponseInfo {
                    header  = "Erro",
                    message = "Informações inválidas recebidas pelo servidor"
                };
                return(JsonConvert.SerializeObject(response));
            }
        }