public ActionResult GetDistrict(string provinceName) //lam theo cai nay { var result = new AjaxOperationResult <IEnumerable <SelectListItem> >(); Country vietnam = AddressUtil.GetINSTANCE().GetCountry(Server.MapPath(AddressUtil.PATH)); Province province = vietnam.VietNamese.Where(p => p.Name.Equals(provinceName)).FirstOrDefault(); IOrderedEnumerable <SelectListItem> districts = null; if (province != null) { //tao ra 1 mang select list item districts = province.Districts.Select(d => new SelectListItem { Text = d.Type + " " + d.Name, //hien len tren dropdown list Value = d.Name //value tra ve cho minh }) .OrderBy(d => d.Value); } result.Succeed = true; result.AdditionalData = districts; return(Json(result)); }
// GET: Place public ActionResult Index() { var _sportService = this.Service <ISportService>(); Country vietnam = AddressUtil.GetINSTANCE().GetCountry(Server.MapPath(AddressUtil.PATH)); var sportList = _sportService.getAllSport(); IEnumerable <SelectListItem> selectList = sportList.Select(s => new SelectListItem { Text = s.Name, Value = s.Id.ToString() }).ToArray(); ViewBag.SportList = selectList; var province = vietnam.VietNamese.ToList(); IEnumerable <SelectListItem> provinceList = province.Select(m => new SelectListItem { Text = m.Type + " " + m.Name, Value = m.Name }).OrderBy(s => s.Value).ToArray(); ViewBag.ProvinceList = provinceList; var viewModel = new SearchPlaceViewModel(); return(View(viewModel)); }
public ActionResult GetWard(string district, string provinceName) { Country vietnam = AddressUtil.GetINSTANCE().GetCountry(Server.MapPath(AddressUtil.PATH)); IEnumerable <SelectListItem> wardList = new List <SelectListItem>(); if (district != null && district != "") { var provinceList = vietnam.VietNamese.Where(p => provinceName.Equals(p.Type + " " + p.Name) && p.Districts.Where(f => district.Equals(f.Type + " " + f.Name)).ToList().Count > 0).ToList(); if (provinceList != null && provinceList.Count > 0) { var districtList = provinceList.First().Districts.Where(p => district.Equals(p.Type + " " + p.Name)).ToList(); if (districtList != null && districtList.Count > 0) { var ward = districtList.First().Wards.ToList(); wardList = ward.Select(m => new SelectListItem { Text = m.Type + " " + m.Name, Value = m.Type + " " + m.Name }).OrderBy(s => s.Value).ToArray(); } } } return(Json(wardList, JsonRequestBehavior.AllowGet)); }
public ActionResult GetWard(string provinceName, string districtName) { var result = new AjaxOperationResult <IEnumerable <SelectListItem> >(); Country vietnam = AddressUtil.GetINSTANCE().GetCountry(Server.MapPath(AddressUtil.PATH)); Province province = vietnam.VietNamese.Where(p => p.Name.Equals(provinceName)).FirstOrDefault(); IOrderedEnumerable <SelectListItem> wards = null; if (province != null) { District district = province.Districts .Where(d => d.Name.Equals(districtName)) .FirstOrDefault(); if (district != null) { wards = district.Wards.Select(w => new SelectListItem { Text = w.Type + " " + w.Name, Value = w.Name }) .OrderBy(w => w.Value); } } result.Succeed = true; result.AdditionalData = wards; return(Json(result)); }
public IOrderedEnumerable <SelectListItem> GetProvince() { Country vietnam = AddressUtil.GetINSTANCE().GetCountry(Server.MapPath(AddressUtil.PATH)); //Province province = vietnam.VietNamese.Where(p => p.Name.Equals(detail.City)).FirstOrDefault(); IOrderedEnumerable <SelectListItem> provinces = vietnam.VietNamese.Select(p => new SelectListItem { Text = p.Type + " " + p.Name, Value = p.Type + " " + p.Name }) .OrderBy(p => p.Value); return(provinces); }
public ActionResult Detail(string id) { var service = this.Service <IAspNetUserService>(); var entity = service.FindUser(id); AccountDetailViewModel model; if (entity == null) { return(this.IdNotFound()); } else { model = Mapper.Map <AccountDetailViewModel>(entity); Country vietnam = AddressUtil.GetINSTANCE().GetCountry(Server.MapPath(AddressUtil.PATH)); Province province = vietnam.VietNamese.Where(p => p.Name.Equals(model.City)).FirstOrDefault(); if (province != null) { model.City = province.Type + " " + province.Name; District district = province.Districts.Where(d => d.Name.Equals(model.District)).FirstOrDefault(); if (district != null) { model.District = district.Type + " " + district.Name; Ward ward = district.Wards.Where(d => d.Name.Equals(model.Ward)).FirstOrDefault(); if (ward != null) { model.Ward = ward.Type + " " + ward.Name; } } } model.CreateAddressString(); model.CreateBirthdayString(); model.CreateRole(); if (model.Gender.HasValue) { model.GenderString = Utils.GetEnumDescription((Gender)model.Gender); } } return(this.PartialView(model)); }
public ActionResult GetDistrict(string provinceName) { Country vietnam = AddressUtil.GetINSTANCE().GetCountry(Server.MapPath(AddressUtil.PATH)); IEnumerable <SelectListItem> districtList = new List <SelectListItem>(); if (provinceName != null || provinceName != "") { var province = vietnam.VietNamese.Where(p => p.Name.Equals(provinceName)).ToList(); if (province != null && province.Count > 0) { var district = province.First().Districts.ToList(); districtList = district.Select(m => new SelectListItem { Text = m.Type + " " + m.Name, Value = m.Name }).OrderBy(s => s.Value).ToArray(); } } return(Json(districtList, JsonRequestBehavior.AllowGet)); }
public ActionResult GetDistrict(string provinceName) { var result = new AjaxOperationResult <IEnumerable <SelectListItem> >(); Country vietnam = AddressUtil.GetINSTANCE().GetCountry(Server.MapPath(AddressUtil.PATH)); Province province = vietnam.VietNamese.Where(p => (p.Type + " " + p.Name).Equals(provinceName)).FirstOrDefault(); IOrderedEnumerable <SelectListItem> districts = null; if (province != null) { districts = province.Districts.Select(d => new SelectListItem { Text = d.Type + " " + d.Name, Value = d.Type + " " + d.Name }) .OrderBy(d => d.Value); } result.Succeed = true; result.AdditionalData = districts; return(Json(result)); }
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)); }
// GET: Profile public ActionResult Index(string userId) { var _userService = this.Service <IAspNetUserService>(); var _sportService = this.Service <ISportService>(); var _followService = this.Service <IFollowService>(); var _groupService = this.Service <IGroupService>(); Country vietnam = AddressUtil.GetINSTANCE().GetCountry(Server.MapPath(AddressUtil.PATH)); var province = vietnam.VietNamese.ToList(); IEnumerable <SelectListItem> provinceList = province.Select(m => new SelectListItem { Text = m.Type + " " + m.Name, Value = m.Type + " " + m.Name }).OrderBy(s => s.Value).ToArray(); ViewBag.ProvinceList = provinceList; AspNetUser user = _userService.FirstOrDefaultActive(u => u.Id.Equals(userId)); if (user == null) { return(RedirectToAction("PageNotFound", "Errors")); } AspNetUserFullInfoViewModel model = Mapper.Map <AspNetUserFullInfoViewModel>(user); this.PrepareUserInfo(model); //suggest follower List <FollowSuggestViewModel> userList = new List <FollowSuggestViewModel>(); var Coord = new GeoCoordinate(); bool checkNearBy = false; if (user.Longitude != null && user.Latitude != null) { Coord = new GeoCoordinate(user.Latitude.Value, user.Longitude.Value); checkNearBy = true; } var users = _userService.GetActive(p => p.Id != userId && p.Follows.Where(f => f.Active == true && (f.FollowerId == userId)).ToList().Count == 0).ToList(); foreach (var item in users) { FollowSuggestViewModel followsug = Mapper.Map <FollowSuggestViewModel>(item); followsug.weight = 0; foreach (var follow in item.Follows) { if (follow.UserId == user.Id) { followsug.weight += 1; break; } } if (checkNearBy && (item.Longitude != null && item.Latitude != null)) { var userCoord = new GeoCoordinate(item.Latitude.Value, item.Longitude.Value); var dis = Coord.GetDistanceTo(userCoord); if (Coord.GetDistanceTo(userCoord) < 5000) { followsug.weight += 2; } } int hobbyCount = 1; foreach (var hobby in user.Hobbies) { foreach (var curHobby in user.Hobbies) { if (hobby.SportId == curHobby.SportId) { followsug.weight = followsug.weight + hobbyCount * 3; followsug.sameSport = hobbyCount; hobbyCount++; } } } userList.Add(followsug); } List <FollowSuggestViewModel> suggestUserList = userList.OrderByDescending(p => p.weight).Take(10).ToList(); if (suggestUserList != null) { ViewBag.suggestUserList = suggestUserList; } //get sport list for post var sports = _sportService.GetActive() .Select(s => new SelectListItem { Text = s.Name, Value = s.Id.ToString() }).OrderBy(s => s.Value); ViewBag.Sport = sports; //get all image of user ViewBag.userPostImages = this.GetAllPostImageOfUser(userId, 0, 12).ToList(); //get all people that this user follow List <Follow> following = _followService.GetFollowingList(userId).ToList(); List <AspNetUser> followingUsers = new List <AspNetUser>(); foreach (var item in following) { AspNetUser us = _userService.FirstOrDefaultActive(u => u.Id == item.UserId); followingUsers.Add(us); } ViewBag.followingUsers = followingUsers; //get list group that this user joined List <Group> groupList = _groupService.GetActive(p => p.GroupMembers.Where(f => f.UserId == userId && f.Status == (int)GroupMemberStatus.Approved).ToList().Count > 0).ToList(); if (groupList != null) { ViewBag.GroupList = groupList; } IEnumerable <SelectListItem> districtList = new List <SelectListItem>(); if (model.City != null && model.City != "") { province = vietnam.VietNamese.Where(p => model.City.Equals(p.Type + " " + p.Name)).ToList(); if (province != null && province.Count > 0) { var district = province.First().Districts.ToList(); districtList = district.Select(m => new SelectListItem { Text = m.Type + " " + m.Name, Value = m.Type + " " + m.Name }).OrderBy(s => s.Value).ToArray(); } } ViewBag.DistrictList = districtList; string curUserId = User.Identity.GetUserId(); //get list of user that this user is following List <Follow> followingList = _followService.GetActive(f => f.FollowerId == curUserId).ToList(); List <FollowDetailViewModel> followingListVM = Mapper.Map <List <FollowDetailViewModel> >(followingList); foreach (var item in followingListVM) { AspNetUser ur = _userService.FirstOrDefaultActive(u => u.Id.Equals(item.UserId)); AspNetUserViewModel userVM = Mapper.Map <AspNetUserViewModel>(ur); item.User = userVM; } ViewBag.followingList = followingListVM; IEnumerable <SelectListItem> wardList = new List <SelectListItem>(); if (model.District != null && model.District != "") { province = vietnam.VietNamese.Where(p => model.City.Equals(p.Type + " " + p.Name) && p.Districts.Where(f => model.District.Equals(f.Type + " " + f.Name)).ToList().Count > 0).ToList(); if (province != null && province.Count > 0) { var districts = province.First().Districts.Where(p => model.District.Equals(p.Type + " " + p.Name)).ToList(); if (districts != null && districts.Count > 0) { var ward = districts.First().Wards.ToList(); wardList = ward.Select(m => new SelectListItem { Text = m.Type + " " + m.Name, Value = m.Type + " " + m.Name }).OrderBy(s => s.Value).ToArray(); } } } ViewBag.WardList = wardList; return(View(model)); }
public ActionResult Update(string id) { // DateTime birthDay = DateTime.Parse(Request["birthDay"]); var user_service = this.Service <IAspNetUserService>(); var role_service = this.Service <IAspNetRoleService>(); var entity = user_service.FindUser(id); UpdateAccountViewModel detail; if (entity == null) { return(this.IdNotFound()); } else { detail = Mapper.Map <UpdateAccountViewModel>(entity); //detail.CreateAddressString(); //detail.CreateBirthdayString(); detail.CreateRole(); Country vietnam = AddressUtil.GetINSTANCE().GetCountry(Server.MapPath(AddressUtil.PATH)); Province province = vietnam.VietNamese.Where(p => p.Name.Equals(detail.City)).FirstOrDefault(); var provinces = vietnam.VietNamese.Select(p => new SelectListItem { Text = p.Type + " " + p.Name, Value = p.Name }) .OrderBy(p => p.Value); IOrderedEnumerable <SelectListItem> districts = new List <SelectListItem>().OrderBy(d => d.Value); IOrderedEnumerable <SelectListItem> wards = new List <SelectListItem>().OrderBy(d => d.Value); if (province != null) { districts = province.Districts.Select(d => new SelectListItem { Text = d.Type + " " + d.Name, Value = d.Name }) .OrderBy(d => d.Value); District district = province.Districts.Where(d => d.Name.Equals(detail.District)).FirstOrDefault(); if (district != null) { wards = district.Wards.Select(w => new SelectListItem { Text = w.Type + " " + w.Name, Value = w.Name }) .OrderBy(w => w.Value); } } var roles = role_service.Get().ToArray() .Select(r => new SelectListItem { Text = r.Name, Value = r.Id }).OrderBy(r => r.Value); provinces.ToList().Add(new SelectListItem { Text = "", Value = " " }); districts.ToList().Add(new SelectListItem { Text = "", Value = " " }); wards.ToList().Add(new SelectListItem { Text = "", Value = " " }); //roles.ToList().Add(new SelectListItem { Text = "", Value = " " }); ViewBag.Provinces = provinces; ViewBag.Districts = districts; ViewBag.Wards = wards; ViewBag.Roles = roles; } return(this.PartialView(detail)); }
public ActionResult PlaceDetail(int?id) { var _placeService = this.Service <IPlaceService>(); Place place = _placeService.FirstOrDefault(p => p.Id == id.Value); var _placeImageService = this.Service <IPlaceImageService>(); List <PlaceImage> placeImages = _placeImageService.Get(p => p.PlaceId == id.Value).ToList(); Country vietnam = AddressUtil.GetINSTANCE().GetCountry(Server.MapPath(AddressUtil.PATH)); Province province = vietnam.VietNamese.Where(p => (p.Type + " " + p.Name).Equals(place.City)).FirstOrDefault(); var provinces = vietnam.VietNamese.Select(p => new SelectListItem { Text = p.Type + " " + p.Name, Value = p.Type + " " + p.Name }) .OrderBy(p => p.Value); IOrderedEnumerable <SelectListItem> districts = new List <SelectListItem>().OrderBy(d => d.Value); IOrderedEnumerable <SelectListItem> wards = new List <SelectListItem>().OrderBy(d => d.Value); if (province != null) { districts = province.Districts.Select(d => new SelectListItem { Text = d.Type + " " + d.Name, Value = d.Type + " " + d.Name }) .OrderBy(d => d.Value); District district = province.Districts.Where(d => (d.Type + " " + d.Name).Equals(place.District)).FirstOrDefault(); if (district != null) { wards = district.Wards.Select(w => new SelectListItem { Text = w.Type + " " + w.Name, Value = w.Type + " " + w.Name }) .OrderBy(w => w.Value); } } provinces.ToList().Add(new SelectListItem { Text = "", Value = " " }); districts.ToList().Add(new SelectListItem { Text = "", Value = " " }); wards.ToList().Add(new SelectListItem { Text = "", Value = " " }); List <SelectListItem> statuss = new List <SelectListItem>(); statuss.Add(new SelectListItem { Text = Utils.GetEnumDescription(PlaceStatus.Active), Value = Convert.ToString((int)PlaceStatus.Active) }); statuss.Add(new SelectListItem { Text = Utils.GetEnumDescription(PlaceStatus.Repairing), Value = Convert.ToString((int)PlaceStatus.Repairing) }); ViewBag.placeImages = placeImages; ViewBag.provinces = provinces; ViewBag.districts = districts; ViewBag.wards = wards; ViewBag.statusList = statuss; return(View(place)); }
public JsonResult VietNam() { Country vietnam = AddressUtil.GetINSTANCE().GetCountry(Server.MapPath(AddressUtil.PATH)); return(Json(vietnam, JsonRequestBehavior.AllowGet)); }