Exemple #1
0
        public static async Task <AddReportResponse> AddReportAsync(AddReportRequest model)
        {
            int IterationsToRetry    = 5;
            int TimeToSleepForRetry  = 3000;
            AddReportResponse result = new AddReportResponse();

            if (Helpers.ConnectivyHelper.CheckConnectivity() != Enums.ConnectivtyResultEnum.HasConnectivity)
            {
                result.Status  = Enums.ResponseStatus.CommunicationError;
                result.Message = "El dispositivo no pudo comunicarse con el servidor, comprueba que tengas conexión a internet";
                return(result);
            }

            model.token = GetToken();

            for (int i = 0; i <= IterationsToRetry; i++)
            {
                try
                {
                    using (var client = new HttpClient())
                    {
                        var service = $"{Settings.FunctionURL}/api/AddRecordItem/";

                        var    res      = JsonConvert.SerializeObject(model);
                        byte[] byteData = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(model));
                        using (var content = new ByteArrayContent(byteData))
                        {
                            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                            var httpResponse = await client.PostAsync(service, content);

                            result = JsonConvert.DeserializeObject <AddReportResponse>(await httpResponse.Content.ReadAsStringAsync());

                            if (httpResponse.StatusCode == HttpStatusCode.OK)
                            {
                                result.Status = Enums.ResponseStatus.Ok;
                            }
                            else
                            {
                                result.Status = Enums.ResponseStatus.Error;
                                Thread.Sleep(TimeToSleepForRetry);
                            }
                            return(result);
                        }
                    }
                }
                catch (Exception)
                {
                    result.Status  = Enums.ResponseStatus.CommunicationError;
                    result.Message = "Ocurrió un error durante el proceso, por favor intenta de nuevo o espera unos minutos antes de vovler a intentar";
                    Thread.Sleep(TimeToSleepForRetry);
                    continue;
                }
            }
            return(result);
        }
Exemple #2
0
        public void AddReport(AddReportRequest request)
        {
            if (request.PostId.HasValue && request.CommentId.HasValue)
            {
                throw new ArgumentException("Cannot report comment and post at the same time");
            }

            var report = _newReportMapper.Map(request);

            _reportRepository.AddReport(report);
        }
Exemple #3
0
        public override async Task <ReportReply> AddReport(AddReportRequest request, ServerCallContext context)
        {
            var report = new Report
            {
                UserId  = int.Parse(context.GetHttpContext().User.Identity.Name),
                IdiomId = request.IdiomId,
                Text    = request.Text
            };
            await _actions.AddReport(report);

            return(report.ToReply());
        }
        public static IList <string> GetErrorList(this AddReportRequest request)
        {
            var errorList = new List <string>();

            switch (request.Type)
            {
            case Enums.ReportType.FugueInMyAddress:
                if (request.Nis == null)
                {
                    errorList.Add("Debe seleccionar un Nis");
                }
                break;

            case Enums.ReportType.FugueInAnotherAddress:
                if (string.IsNullOrWhiteSpace(request.Report.Street))
                {
                    errorList.Add("La calle es requerida.");
                }
                if (string.IsNullOrWhiteSpace(request.Report.Number))
                {
                    errorList.Add("El número es requerido");
                }
                if (string.IsNullOrWhiteSpace(request.Report.Colony))
                {
                    errorList.Add("La colonia es requerida");
                }
                if (string.IsNullOrWhiteSpace(request.Report.PostalCode))
                {
                    errorList.Add("El código postal es requerido");
                }
                if (string.IsNullOrWhiteSpace(request.Report.References))
                {
                    errorList.Add("Las referencias son requeridas");
                }
                break;

            case Enums.ReportType.FugueInAnotherLocation:
                if (request.Report.Latitude == null || request.Report.Longitude == null)
                {
                    errorList.Add("Debe seleccionar un punto en el mapa");
                }
                break;

            default:
                throw new ArgumentException($"unknown request type {request.Type}");
            }

            if (string.IsNullOrWhiteSpace(request.Report.Comments))
            {
                errorList.Add("Los comentarios adicionales son requeridos.");
            }
            return(errorList.Any() ? errorList : null);
        }
        private async Task SendReport()
        {
            if (!IsBusy)
            {
                IsBusy          = true;
                MessageTitle    = "Enviando...";
                MessageSubTitle = "Espera un momento, el proceso puede tomar unos segundos.";
                item.RecordHash = CreateHash();
                item.DeviceHash = Helpers.HashHelper.GetSha256Hash(Plugin.DeviceInfo.CrossDeviceInfo.Current.Id);
                item.Username   = Settings.Profile_Username;
                var imagefile = Helpers.LocalFilesHelper.ReadFile(item.UID.ToString());
                item.Image = HashHelper.GetSha256Hash(imagefile);
                imagefile  = null;

                AddReportRequest addReportRequest = new AddReportRequest()
                {
                    RecordItem = item
                };

                var response = await RestHelper.AddReportAsync(addReportRequest);

                if (response.Status != Enums.ResponseStatus.Ok)
                {
                    IsContinueGoBackEnabled = true;
                    IsContinueEnabled       = false;
                    MessageTitle            = "Se presentó un problema al realizar el registro.";
                    MessageSubTitle         = response.Message;
                }
                else
                {
                    IsContinueEnabled       = true;
                    IsContinueGoBackEnabled = false;
                    MessageTitle            = $"¡Gracias {Settings.Profile_Username}!";
                    MessageSubTitle         = "Tu registro ha sido completado satisfactoriamente.";

                    Settings.CurrentRecordItem = string.Empty;

                    var count = navigation.NavigationStack.Count;
                    for (int i = 0; i < count - 1; i++)
                    {
                        navigation.RemovePage(navigation.NavigationStack.ElementAt(0));
                    }
                    navigation.InsertPageBefore(new WelcomePage(), navigation.NavigationStack.Last());
                }
            }
            IsBusy = false;
        }
        public void Can_Map_From_AddReportRequest_To_Report()
        {
            //ARRANGE
            var report = new AddReportRequest
            {
                PostId       = null,
                CommentId    = 1,
                ReportTypeId = 3
            };

            //ACT
            var newCommentReportMapper = new NewReportMapper();
            var result = newCommentReportMapper.Map(report);

            //ASSERT
            var expectedResult = new Report
            {
                Post    = null,
                Comment = new Comment {
                    Id = 1
                },
                ReportType = new ReportType {
                    Id = 3
                }
            };

            result.Should().BeEquivalentTo(expectedResult);

            //ARRANGE
            report.PostId    = 1;
            report.CommentId = null;

            //ACT
            result = newCommentReportMapper.Map(report);

            //ASSERT
            expectedResult.Post = new Post {
                Id = 1
            };
            expectedResult.Comment = null;
            result.Should().BeEquivalentTo(expectedResult);
        }
Exemple #7
0
 public void AddReport(AddReportRequest request)
 {
     _addReportModule.AddReport(request);
 }