public async Task <ExtPostContainer <string> > SaveInput(NotificationEventInput input, bool isBatch)
        {
            await Validate(input);

            var id = !string.IsNullOrWhiteSpace(input.Id) ? input.Id : Guid.NewGuid().ToString("N");
            NotificationEvent notification = new NotificationEvent {
                Id                  = id,
                Created             = DateTime.Now,
                IdBarrack           = input.IdBarrack,
                IdPhenologicalEvent = input.IdPhenologicalEvent,
                NotificationType    = input.NotificationType,
                PicturePath         = input.Base64,
                Description         = input.Description,
            };

            if (input.Location != null)
            {
                notification.Location = new Point(input.Location.Longitude, input.Location.Latitude);
                notification.Weather  = await weather.GetWeather((float)input.Location.Latitude, (float)input.Location.Longitude);
            }
            if (!isBatch)
            {
                return(await Save(notification));
            }
            await repo.CreateEntityContainer(notification);

            return(new ExtPostContainer <string> {
                IdRelated = id,
                MessageResult = ExtMessageResult.Ok
            });
        }
        public override async Task <ExtPostContainer <string> > SaveInput(NotificationEventInput input)
        {
            await Validate(input);

            var id          = !string.IsNullOrWhiteSpace(input.Id) ? input.Id : Guid.NewGuid().ToString("N");
            var picturePath = await uploadImage.UploadImageBase64(input.Base64);


            NotificationEvent notification = new NotificationEvent {
                Id                  = id,
                Created             = DateTime.Now,
                IdBarrack           = input.IdBarrack,
                IdPhenologicalEvent = input.IdPhenologicalEvent,
                NotificationType    = input.NotificationType,
                PicturePath         = picturePath,
                Description         = input.Description,
            };

            //TODO: Cambiar tipo de dato a GeoSpacial
            #if !CONNECT
            if (input.Location != null)
            {
                notification.Location = new Point(input.Location.Lng, input.Location.Lat);
                notification.Weather  = await weather.GetWeather((float)input.Location.Lat, (float)input.Location.Lng);
            }
            #endif

            await SaveDb(notification);

            var usersEmails = await commonQueries.GetUsersMailsFromRoles(new List <string> {
                "24beac75d4bb4f8d8fae8373426af780"
            });

            email.SendEmail(usersEmails, "Notificacion",
                            $@"<html>
                    <body>
                        <p> Estimado(a), </p>
                        <p> Llego una notificacion </p>
                        <img src='{picturePath}' style='width:50%;height:auto;'>
                        <p> Atentamente,<br> -Aresa </br></p>
                    </body>
                </html>");

            return(await SaveSearch(notification));
        }
Exemple #3
0
        public JsonResult GetLocation(string location)
        {
            // IF the User denied the location access, Widget will return unavailable.
            if (location == "UnAvailable")
            {
                return(Json(new { isSucess = false, location = "" }));
            }
            // Else continue calling the API
            WidgetResponse widgetResponse = new WidgetResponse();

            // Get if the session is available
            if (_session != null && !string.IsNullOrEmpty(_session.GetString("Location")))
            {
                widgetResponse.Address       = _session.GetString("Address");
                widgetResponse.FeelsLikeTemp = Convert.ToInt32(_session.GetString("FeelsLikeTemp"));
                widgetResponse.Icon          = _session.GetString("Icon");
                widgetResponse.Ozone         = Convert.ToDouble(_session.GetString("Ozone"));
                widgetResponse.Temp          = Convert.ToInt32(_session.GetString("Temp"));
                widgetResponse.Aqi           = _session.GetString("Aqi");
            }
            else
            {
                _session.SetString("Location", location);
                ViewData["Location"] = location;
                WeatherRequest weatherRequest = new WeatherRequest();
                weatherRequest.Latitude  = Convert.ToDouble(location.Split(',')[0]);
                weatherRequest.Longitude = Convert.ToDouble(location.Split(',')[1]);
                try
                {
                    widgetResponse = _weatherApi.GetWeather(weatherRequest);
                    _session.SetString("Address", widgetResponse.Address);
                    _session.SetString("FeelsLikeTemp", widgetResponse.FeelsLikeTemp.ToString());
                    _session.SetString("Icon", widgetResponse.Icon);
                    _session.SetString("Ozone", widgetResponse.Ozone.ToString());
                    _session.SetString("Temp", widgetResponse.Temp.ToString());
                    _session.SetString("Aqi", widgetResponse.Aqi.ToString());
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex.StackTrace);
                }
            }
            return(Json(new { isSucess = true, location = widgetResponse }));
        }
Exemple #4
0
        async Task GetWeather()
        {
            try
            {
                var current = Connectivity.NetworkAccess;
                if (current == NetworkAccess.Internet)
                {
                    CityWeather = await apiService.GetWeather(InputCity);

                    ImageLink = $"http://openweathermap.org/img/wn/{CityWeather.Weather[0].Icon}@2x.png";
                }
                else
                {
                    await App.Current.MainPage.DisplayAlert("Error", "You don't have internet connection", "Ok");
                }
            }
            catch (Exception ex)
            {
                await App.Current.MainPage.DisplayAlert("Error", "Unable to connect to the server", "Ok");
            }
        }