Esempio n. 1
0
        public string UploadImage(byte[] msgArray, string user_id, string display_name)
        {
            var    today    = timeService.GetLocalDateTime(LocalTimeService.CHINA_STANDARD_TIME);
            var    client   = new ImgurClient(IMGUR_CLIENT_ID, IMGUR_CLIENT_SECRET);
            var    endpoint = new ImageEndpoint(client);
            IImage image;

            Stream stream = new MemoryStream(msgArray);

            using (stream)
            {
                image = endpoint.UploadImageStreamAsync(stream).GetAwaiter().GetResult();
            }
            using (var db = new LineModel())
            {
                var instance = new UploadImage
                {
                    addTime  = today,
                    flg      = false,
                    imageUrl = image.Link,
                    userId   = user_id,
                    userName = display_name
                };
                db.UploadImage.Add(instance);
                db.SaveChanges();

                var status = db.UploadStatus.Where(x => x.UserId == user_id && x.CommandStr == "--upload").ToList();
                db.UploadStatus.RemoveRange(status);

                db.SaveChanges();
            }
            return(image.Link);
        }
Esempio n. 2
0
        public string GetATMovieTimeAsync(string location, string keyword)
        {
            LocalTimeService timeService = new LocalTimeService();
            var today = timeService.GetLocalDateTime(LocalTimeService.CHINA_STANDARD_TIME).Date;
            var str   = "";

            for (int count = 0; count < 3; count++)
            {
                var movieDate = today.AddDays(count).ToString("yyyy/MM/dd");
                var url       = $"http://www.ambassador.com.tw/ambassadorsite.webapi/api/Movies/GetShowtimeListForTheater/?theaterId={atMovieDict[location]}&showingDate={movieDate}";
                using (HttpClient client = new HttpClient())
                {
                    var response = client.GetStringAsync(url).Result;
                    var json     = JsonConvert.DeserializeObject <List <ATMovieModel> >(response).Where(x => x.Name.Contains(keyword)).ToList();
                    for (int i = 0; i < json.Count; i++)
                    {
                        str += json[i].PeriodShowtime[0].PlayingDate.ToString("yyyy/MM/dd") + "\r\n";
                        foreach (var item in json[i].PeriodShowtime)
                        {
                            str += item.AssistantName + "\r\n";
                            var timeArray = string.Join(" | ", item.Showtimes);
                            str += timeArray + "\r\n";
                        }
                        str += "============\r\n";
                    }
                }
            }


            return(str);
        }