Пример #1
0
        public async Task <IActionResult> AddStation([FromBody] Mapping map)
        {
            if (map == null)
            {
                return(BadRequest(new ResponseModel {
                    Message = "Missing mapping object"
                }));
            }

            if (await _db.Mappings.AnyAsync(s => s.Text == map.Text))
            {
                return(BadRequest(new ResponseModel {
                    Message = "Mapping already exists"
                }));
            }

            try {
                await _db.Mappings.AddAsync(map);

                await _db.SaveChangesAsync();

                return(Ok(new ResponseModel {
                    Message = "Mapping added", Data = map
                }));
            }
            catch (Exception) {
                return(StatusCode(500, new ResponseModel {
                    Message = "Problems while adding new mapping"
                }));
            }
        }
Пример #2
0
        public async Task <IActionResult> AddStation([FromBody] Station station)
        {
            if (station == null)
            {
                return(BadRequest(new ResponseModel {
                    Message = "Missing station object"
                }));
            }

            if (await _db.Stations.AnyAsync(s => s.PlaylistUrl.ToLower() == station.PlaylistUrl.ToLower()))
            {
                return(BadRequest(new ResponseModel {
                    Message = "PlaylistUrl already crawled"
                }));
            }

            try {
                await _db.Stations.AddAsync(station);

                await _db.SaveChangesAsync();

                return(Ok(new ResponseModel {
                    Message = "Station added", Data = station
                }));
            } catch (Exception) {
                return(StatusCode(500, new ResponseModel {
                    Message = "Problems while adding new station"
                }));
            }
        }
Пример #3
0
        private async Task <int> AddLineInfo(string departCity, string arriveCity, string port, string lineTitle, string days, string scenic, string hotels, string supplier, string pmRecommendation, string url, int soldqty, int commentNumber, string lineNo, string cityCode)
        {
            Guid     lineguid = Guid.NewGuid();
            DateTime date     = DateTime.Now;

            _dbContext.T_Line.Add(new Line()
            {
                Id               = lineguid,
                SiteName         = "途牛",
                TypeName         = "自助游",
                Departcity       = departCity,
                ArriveCity       = arriveCity,
                Port             = port,
                Linetitle        = lineTitle,
                Days             = days,
                Scenic           = scenic,
                Hotels           = hotels,
                Supplier         = supplier,
                Traffic          = String.Empty,
                Trafficdetail    = String.Empty,
                Soldqty          = soldqty,
                Url              = url,
                Reco             = string.Empty,
                CreateDate       = date,
                CommentNumber    = commentNumber,
                PmRecommendation = pmRecommendation
            });
            //if (num <= 0) return num;

            #region 抓取价格日历json

            var webclient = new WebClient {
                Encoding = System.Text.Encoding.UTF8
            };
            //定义以UTF-8格式接收文本信息,规避WebClient接收文本信息时夹带乱码问题
            urlPrice = $"http://www.tuniu.com//package/api/calendar?productId={lineNo}&bookCityCode={cityCode}";
            var htmlPrice = webclient.DownloadString(urlPrice);


            ParseJson jobInfoList = JsonConvert.DeserializeObject <ParseJson>(htmlPrice);

            if (jobInfoList == null || jobInfoList.Success != true || jobInfoList.Data?.CalendarInfo == null)
            {
                return(-1);
            }


            foreach (var t in jobInfoList.Data.CalendarInfo)
            {
                adultPrice = t.AdultPrice;
                childPrice = t.ChildPrice;
                Groupdate  = t.PlanDate;
                if (!string.IsNullOrEmpty(Groupdate))
                {
                    Guid groupPriceGuid = Guid.NewGuid();
                    _dbContext.T_GroupPrice.Add(new GroupPrice()
                    {
                        Id         = groupPriceGuid,
                        Lineid     = lineguid,
                        GroupDate  = Groupdate,
                        AdultPrice = adultPrice,
                        ChildPrice = childPrice
                    });

                    //dbContext.Entry<GroupPrice>(new GroupPrice()
                    //{
                    //    Id = groupPriceGuid,
                    //    Lineid = lineguid,
                    //    GroupDate = Groupdate,
                    //    AdultPrice = adultPrice,
                    //    ChildPrice = childPrice


                    //}).State = EntityState.Added;
                }
            }
            return(await _dbContext.SaveChangesAsync());



            #endregion
        }