private async void SendLocationMessageCommandExecute()
        {
            this.SendingMessage = true;
            HttpResponseMessage response = null;

            var locator  = CrossGeolocator.Current;
            var position = await locator.GetPositionAsync(5000);

            var request = new AddLocationMessageRequest();

            request.CallerIdentifier = CrossSettings.Current.GetValueOrDefault("CallerIdentifier", string.Empty);
            request.DeviceIdentifier = CrossSettings.Current.GetValueOrDefault("DeviceIdentifier", string.Empty);
            request.ChatIdentifier   = this.ChatId;
            request.Latitude         = (long)position.Latitude;
            request.Longitude        = (long)position.Longitude;
            request.Message          = this.Text;

            string url = $"{base.BaseUrl}/Message/AddLocationMessage";

            try
            {
                var formData = request.GetFormData();
                response = await base.Client.PostAsync(url, formData);
            }
            catch (Exception)
            {
            }

            if (response != null && response.IsSuccessStatusCode)
            {
                var content = await response.Content.ReadAsStringAsync();

                var result = JsonConvert.DeserializeObject <LocationMessage>(content);
                this.Messages.Add(result);
                this.Text = string.Empty;
                mvvm.Messenger.Default.Send <SetFocusMessage>(new SetFocusMessage()
                {
                    ControlName = "First"
                });
            }
            else
            {
                mvvm.Messenger.Default.Send <PromptMessage>(new PromptMessage("OOPPSS", "Qualcosa è andato storto!"));
            }

            this.SendingMessage = false;
        }
Esempio n. 2
0
        public IActionResult AddLocationMessage([FromForm] AddLocationMessageRequest request)
        {
            if (request == null)
            {
                return(BadRequest("Unable to locate the body request"));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var exist = chatRepository.Exist(request.ChatIdentifier);

            if (!exist)
            {
                return(BadRequest("Unable to locate the specified chat."));
            }

            var message = messageRepository.AddLocationMessage(request.Message, request.ChatIdentifier, request.Latitude,
                                                               request.Longitude);

            return(Created(new Uri($"/api/message/get/{message.Id}", UriKind.Relative), message));
        }