コード例 #1
0
        public async Task <ActionResult <Coffee> > Create(Coffee coffee)
        {
            var identity = User.Identity as ClaimsIdentity;
            var id       = identity.Claims.First((c) => c.Type == ClaimTypes.PrimarySid);

            coffee.UserId    = id.Value;
            coffee.CreatedAt = DateTime.Now;

            if (!string.IsNullOrEmpty(coffee.Latitude) && !string.IsNullOrEmpty(coffee.Longitude))
            {
                var lat = float.Parse(coffee.Latitude);
                var lon = float.Parse(coffee.Longitude);

                if (!float.IsNaN(lat) && !float.IsNaN(lon))
                {
                    try
                    {
                        coffee.Weather = await _weatherService.GetWeather(lat, lon);
                    }
                    catch (Exception e)
                    {
                        _logger.LogError(e, "Could not add weather to coffee");
                    }
                }
            }

            _coffeeService.Create(coffee);
            return(CreatedAtRoute("GetCoffee", new { id = coffee.Id.ToString() }, coffee));
        }
コード例 #2
0
 public Task <Coffee> Create([FromBody] Coffee coffee)
 {
     return(_coffeeService.Create(coffee));
 }