Exemplo n.º 1
0
        public StoreExtensions.AsyncActionCreator <ApplicationState> UploadWrongPlaceReport(string reasonComment, bool isNotSkateboardPlace)
        {
            return(async(dispatch, getState) =>
            {
                var state = getState();
                long userId = GetUserId(state.UserState.User);

                var wrongPlaceReport = new WrongPlaceReport(
                    placeId: state.PlacesData.CurrentPlaceState.Value.Id,
                    placeVersion: state.PlacesData.CurrentPlaceState.Value.Version,
                    userId: userId,
                    deviceId: DeviceInfo.Id,
                    reasonComment: reasonComment,
                    isNotSkateboardPlace: isNotSkateboardPlace
                    );

                dispatch(new SetWrongPlaceReportStartAction(wrongPlaceReport));

                try
                {
                    await WrongPlaceReportService.SendAsync(wrongPlaceReport);

                    dispatch(new SetWrongPlaceReportCompleteAction(wrongPlaceReport));
                }
                catch (Exception e)
                {
                    dispatch(new SetWrongPlaceReportCompleteAction(e));
                }
            });
        }
        public async Task SendAsync(WrongPlaceReport wrongPlaceReport)
        {
            try
            {
                var uri      = new Uri(urlRepository.PostWrongPlaceReportUri);
                var response = await httpClient.PostAsync(uri, CreateStringContent(wrongPlaceReport));

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    return;
                }

                if (response.StatusCode == HttpStatusCode.BadRequest)
                {
                    var responseJson = await response.Content.ReadAsStringAsync();

                    var message = JObject.Parse(responseJson)["message"].ToString();
                    throw new Exception(message);
                }
            }
            catch (Exception e)
            {
                //TODO: Log...
                throw new Exception(e.Message);
            }
        }
Exemplo n.º 3
0
        public SetWrongPlaceReportStartAction(WrongPlaceReport wrongPlaceReport)
        {
            if (wrongPlaceReport == null)
            {
                throw new ArgumentException("You cannot set null as WrongPlaceReport.");
            }

            Status = Status.Setting;
        }
Exemplo n.º 4
0
 public SetWrongPlaceReportCompleteAction(WrongPlaceReport wrongPlaceReport)
 {
     WrongPlaceReport = wrongPlaceReport ?? throw new ArgumentException("WrongPlaceReport cannot be null.");
     Status           = Status.Success;
 }