Exemple #1
0
        public ActionResult ChangePlaceStatus(int id, int status)
        {
            var service = this.Service <IPlaceService>();

            ResponseModel <PlaceOveralViewModel> response = null;

            try
            {
                Place place = service.ChangeStatus(id, status);
                if (place != null)
                {
                    PlaceOveralViewModel result = Mapper.Map <PlaceOveralViewModel>(place);

                    PreparePlaceOveralViewModel(result);

                    response = new ResponseModel <PlaceOveralViewModel>(true, "Trạng thái đã được cập nhật!", null, result);
                }
                else
                {
                    response = ResponseModel <PlaceOveralViewModel> .CreateErrorResponse("Cập nhật trạng thái thất bại!", systemError);
                }
            }
            catch (Exception e)
            {
                response = ResponseModel <PlaceOveralViewModel> .CreateErrorResponse("Cập nhật trạng thái thất bại!", systemError);
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Exemple #2
0
 private void PreparePlaceOveralViewModel(PlaceOveralViewModel p)
 {
     p.StatusString = Utils.GetEnumDescription((PlaceStatus)p.Status);
 }
        public ActionResult GetData(JQueryDataTableParamModel param, string sport, string province,
                                    string district, string lat, string lng)
        {
            var          _placeService             = this.Service <IPlaceService>();
            List <Place> placeList                 = new List <Place>();
            List <PlaceOveralViewModel> resultList = new List <PlaceOveralViewModel>();

            if (lat != null && lat != "" && lng != null && lng != "")
            {
                var places = _placeService.getAllPlace();
                if (sport != null && sport != "")
                {
                    int sportID = Int32.Parse(sport);
                    places = _placeService.GetActive(p => p.Approve && (p.Status == (int)PlaceStatus.Active || p.Status == (int)PlaceStatus.Repairing) &&
                                                     p.Fields.Where(f => f.FieldType.SportId == sportID).ToList().Count > 0);
                }
                var latitude   = float.Parse(lat);
                var longtitude = float.Parse(lng);
                var Coord      = new GeoCoordinate(latitude, longtitude);
                foreach (Place place in places)
                {
                    var placeCoord = new GeoCoordinate(place.Latitude.Value, place.Longitude.Value);
                    var dis        = Coord.GetDistanceTo(placeCoord);
                    if (Coord.GetDistanceTo(placeCoord) < 5000)
                    {
                        placeList.Add(place);
                    }
                }
            }
            else
            {
                var     tmp     = province;
                Country vietnam = AddressUtil.GetINSTANCE().GetCountry(Server.MapPath(AddressUtil.PATH));
                IEnumerable <SelectListItem> districtList = new List <SelectListItem>();
                if (province != null || province != "")
                {
                    var provinceName = vietnam.VietNamese.Where(p => p.Name.Equals(province)).ToList();
                    if (province != null && provinceName.Count > 0)
                    {
                        var p = provinceName.First().Type;
                        province = p + " " + province;
                    }
                }

                IEnumerable <SelectListItem> wardList = new List <SelectListItem>();
                if (district != null || district != "")
                {
                    var provinceList = vietnam.VietNamese.Where(p => p.Name.Equals(tmp) && p.Districts.Where(f =>
                                                                                                             f.Name == district).ToList().Count > 0).ToList();
                    if (provinceList != null && provinceList.Count > 0)
                    {
                        var districts = provinceList.First().Districts.Where(p => p.Name == district).ToList();
                        if (districts != null && districts.Count > 0)
                        {
                            var d = districts.First().Type;
                            district = d + " " + district;
                        }
                    }
                }
                placeList = _placeService.getPlace(sport, province, district).ToList();
            }

            if (placeList != null && placeList.Count > 0)
            {
                var rateService = this.Service <IRatingService>();
                foreach (var item in placeList)
                {
                    PlaceOveralViewModel model = Mapper.Map <PlaceOveralViewModel>(item);
                    var    rates        = rateService.GetActive(p => p.PlaceId == item.Id).ToList();
                    double averagePoint = 0;
                    if (rates != null && rates.Count > 0)
                    {
                        foreach (var itemRate in rates)
                        {
                            averagePoint += itemRate.Point;
                        }
                        averagePoint = averagePoint / rates.Count;
                    }
                    model.rate = averagePoint;
                    resultList.Add(model);
                }
            }

            IEnumerable <PlaceOveralViewModel> filteredListItems;

            if (!string.IsNullOrEmpty(param.sSearch))
            {
                filteredListItems = resultList.Where(
                    d => (d.Name != null && d.Name.ToLower().Contains(param.sSearch.ToLower()))
                    ).OrderByDescending(p => p.rate);
            }
            else
            {
                filteredListItems = resultList.OrderByDescending(p => p.rate);
            }
            // Sort.
            var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]);
            var sortDirection   = Request["sSortDir_0"]; // asc or desc

            switch (sortColumnIndex)
            {
            case 2:
                filteredListItems = sortDirection == "asc"
                        ? filteredListItems.OrderBy(c => c.Name)
                        : filteredListItems.OrderByDescending(c => c.Name);
                break;
            }

            var displayedList = filteredListItems.Skip(param.iDisplayStart).Take(param.iDisplayLength);
            var result        = displayedList.Select(c => new IConvertible[] {
                c.Id,
                (c.Avatar == null || c.Avatar.Equals(""))?"/Content/images/no_image.jpg":c.Avatar,
                c.Name,
                c.Description.Length > 130? c.Description.Substring(0, 130) + "...": c.Description,
                (c.Address + ", " + c.District + ", " + c.City).Length < 40? (c.Address + ", " + c.District + ", " + c.City):
                (c.Address + ", " + c.District + ", " + c.City).Substring(0, 40) + "...",
                c.PhoneNumber
            }.ToArray());

            return(Json(new
            {
                param.sEcho,
                iTotalRecords = result.Count(),
                iTotalDisplayRecords = filteredListItems.Count(),
                aaData = result
            }, JsonRequestBehavior.AllowGet));
        }