Exemplo n.º 1
0
        public async Task SetLocation([Remainder] string location)
        {
            IGuildUser guser = Context.Message.Author as IGuildUser;
            EntityUser user  = new EntityUser(guser);

            if (_userRepo.GetUserById(user.Id) != null)
            {
                user = _userRepo.GetUserById(user.Id);
            }

            //check if location exists
            WeatherModel wm = await WeatherProcessor.GetWeatherDataName(location);

            if (wm == null)
            {
                throw new NoLocationFoundException();
            }

            if (_repo.UserHasLocation(user))
            {
                _repo.ChangeLocation(user, location);
                _repo.SaveChanges();
                await Context.Channel.SendMessageAsync($"Location updated to {location}");
            }
            else
            {
                _repo.AddLocation(user, location);
                _repo.SaveChanges();
                await Context.Channel.SendMessageAsync($"Location set to {location}");
            }
        }