Example #1
0
        //Update PlaceKind
        public IHttpActionResult Update(PlaceKindViewModel PlaceKindViewModel)
        {
            var pk = _PlaceKindService.GetPlaceKind(PlaceKindViewModel.Id);

            pk.Kind        = PlaceKindViewModel.Kind;
            pk.Description = PlaceKindViewModel.Description;
            pk.DateCreate  = DateTime.Now;
            _PlaceKindService.EditPlaceKind(pk);
            return(Ok());
        }
Example #2
0
        public IHttpActionResult CreatePlaceByNormalUser(PlaceViewModel place)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            Place p = new Place();

            p.Address     = place.Address;
            p.Description = place.Description;
            p.Facebook    = place.Facebook;
            p.Instagram   = place.Instagram;
            p.Longitude   = place.Longitude;
            p.Latitude    = place.Latitude;
            p.Name        = place.Name;
            p.NofSearch   = place.NofSearch;
            p.PageUrl     = place.PageUrl;
            p.PhoneNumber = place.PhoneNumber;
            p.PlaceKindId = place.PlaceKindId;
            p.Poppular    = place.Poppular;
            p.RootPlaceId = place.RootPlaceId;
            p.RatingStar  = place.RatingStar;
            p.ServeStatus = place.ServeStatus;
            p.TimeOpen    = place.TimeOpen;
            p.TimeClose   = place.TimeClose;
            p.UserId      = place.UserId;
            p.ZoomSize    = place.ZoomSize;
            p.DateCreate  = DateTime.Now;
            p.LastConfirm = DateTime.Now;
            p.ZoomSize    = "16";
            p.NofSearch   = 0;
            p.Promote     = 0;

            PlaceKind pk = _PlaceKindService.GetPlaceKind(place.PlaceKindId);

            p.Poppular = (100 - pk.Priority) * 100 + (place.RatingStar * 10) + p.Promote;

            p.Definition = convertToUnSign3(place.Name + " " + place.Address);

            p.isEnable = false;
            _PlaceService.CreatePlace(p);
            return(Ok());
        }
Example #3
0
        public IHttpActionResult Insert([FromBody] CrawPlaceViewModel[] cvmds)
        {
            try
            {
                foreach (CrawPlaceViewModel cvmd in cvmds)
                {
                    var pAddress  = _PlaceService.GetPlaceByAddress(cvmd.address);
                    var upAddress = _PlaceService.GetPlaceByAddress(convertToUnSign3(cvmd.address)); //unsigned UTF-8
                    var pName     = _PlaceService.GetPlace(cvmd.title);
                    var upName    = _PlaceService.GetPlace(convertToUnSign3(cvmd.title));            //unsigned UTF8

                    //if not exist add place with (sign/usigned) name/address tag  OR new address
                    if ((pName == null && upName == null && upAddress == null && pAddress == null) || (pAddress == null && upAddress == null))
                    {
                        PlaceKind pk = _PlaceKindService.GetPlaceKind(cvmd.category);
                        if (pk == null)
                        {
                            placeKind            = new PlaceKind();
                            placeKind.DateCreate = DateTime.Today;
                            string pkind = "";
                            switch (cvmd.category)
                            {
                            case "Nhà hàng": pkind = "Restaurant"; break;

                            case "Café": pkind = "Cafe"; break;

                            case "Khách sạn và chỗ ở": pkind = "Hotel"; break;

                            case "Mua sắm": pkind = "Market"; break;

                            case "Giáo dục": pkind = "Education"; break;

                            case "Du lịch": pkind = "Point_of_interested"; break;

                            case "Sức khỏe": pkind = "Health"; break;

                            case "Làm đẹp": pkind = "Spa"; break;

                            case "Giải trí": pkind = "Entertaiment"; break;

                            case "Cây xăng": pkind = "Gas"; break;

                            case "Các cây ATM": pkind = "ATM"; break;

                            case "Cuộc sống về đêm": pkind = "NightLife"; break;

                            case "Dịch vụ": pkind = "Service"; break;
                            }
                            placeKind.Kind        = pkind;
                            placeKind.Description = cvmd.category;
                            _PlaceKindService.CreatePlaceKind(placeKind);
                        }
                        place             = new Place();
                        place.Address     = cvmd.address;
                        place.Description = cvmd.description;
                        place.Facebook    = cvmd.facebook;
                        place.DateCreate  = DateTime.Today;
                        place.LastConfirm = DateTime.Today;
                        place.isEnable    = true;
                        place.Latitude    = cvmd.gps.latitude;
                        place.Longitude   = cvmd.gps.longitude;
                        place.Name        = cvmd.title;
                        place.PageUrl     = cvmd.url;
                        place.PhoneNumber = cvmd.phone;
                        place.RatingStar  = cvmd.rating;
                        place.ServeStatus = 1; //active
                        place.UserId      = 0; //admin
                        place.RootPlaceId = 0; //VietNam
                        place.TimeOpen    = 0000;
                        place.PlaceKindId = _PlaceKindService.GetPlaceKind(cvmd.category).Id;
                        place.PlaceKind   = pk;
                        place.TimeClose   = 0000;
                        place.ZoomSize    = "16";
                        place.NofSearch   = 0;
                        place.Promote     = 0;

                        place.Poppular = (100 - pk.Priority) * 100 + (place.RatingStar * 10) + place.Promote;

                        place.Definition = convertToUnSign3(cvmd.title + " " + cvmd.address);
                        _PlaceService.CreatePlace(place);


                        Image img = _ImageService.GetImage(cvmd.img_big);
                        if (img == null)
                        {
                            image             = new Image();
                            image.ImageKindId = _ImageKindService.GetImageKind("Place").Id;
                            image.DateCreate  = DateTime.Today;
                            image.ImageKind   = _ImageKindService.GetImageKind(2);
                            image.OwnId       = _PlaceService.GetPlace(cvmd.title).Id;
                            image.Description = cvmd.title + " : " + cvmd.address;
                            image.Url         = cvmd.img_big;
                            _ImageService.CreateImage(image);
                        }
                        //break;//test: add only one none exist place in db
                    }
                }
            }
            catch (Exception e)
            {
                return(Content(HttpStatusCode.BadRequest, e.Message + " : " + e.InnerException + " : " + e.StackTrace + " : " + e.Data));
            }
            return(Ok());
        }