Пример #1
0
 public ActionResult SubCategoryUpdate(SubCategory model, HttpPostedFileBase uploadIcon)
 {
     int ctId = model.CategoryId;
     if (ModelState.IsValid)
     {
         if (uploadIcon != null && uploadIcon.ContentLength > 0)
         {
             model.Icon = ImageUploadExtension.renameUploadIcon(uploadIcon);
         }
         if (model.Id == 0)
         {
             model.isActive = true;
             dbContext.SubCategories.Add(model);
             dbContext.SaveChanges();
         }
         else
         {
             SubCategory sc = dbContext.SubCategories.Find(model.Id);
             sc.Name = model.Name;
             if (model.Icon != null)
             {
                 sc.Icon = model.Icon;
             }
             dbContext.Entry(sc).State = EntityState.Modified;
             dbContext.SaveChanges();
         }
     }
     return RedirectToAction("ManageSubCategory", "Administrator", new { id = ctId });
 }
Пример #2
0
 public JsonResult GetPlaceInRadius(int radius, double lat, double lng, string search)
 {
     var places = db.Places.Where(p => p.IsActive == true).Select(p => new { p.Id, p.Name, p.SubCategoryId, p.Address, Latitude = p.Coordinate.Latitude, Longitude = p.Coordinate.Longitude, Icon = p.SubCategory.Icon.Substring(1, (p.SubCategory.Icon.Length - 1)), LowPrice = p.Items.Count > 0 ? p.Items.FirstOrDefault().Price : 0 }).ToList();
     var locA = new GeoCoordinate(lat, lng);
     foreach (var place in places.ToList())
     {
         var locB = new GeoCoordinate(place.Latitude, place.Longitude);
         if (locA.GetDistanceTo(locB) > radius)
         {
             places.Remove(place);
         }
     }
     //Search
     if (search != null && search.Trim().Length > 0)
     {
         search = search.Trim().ToLower().ToUnsign();
         List<int> placebyitem = new List<int>();
         foreach (var item in db.Items)
         {
             if (placebyitem.Contains(item.PlaceId))
                 continue;
             var name = item.Name.ToLower().ToUnsign();
             if (BreakStringsAndCheck(search, name) >= 50 || name.Contains(search))
             {
                 placebyitem.Add(item.PlaceId);
             }
         }
         places = places.Where(p => BreakStringsAndCheck(search, p.Name.ToLower().ToUnsign()) >= 50 || p.Name.ToLower().ToUnsign().Contains(search) || placebyitem.Contains(p.Id)).ToList();
     }
     List<SubCategory> numOfPlaces = new List<SubCategory>();
     foreach (int sub in db.SubCategories.Select(s => s.Id))
     {
         SubCategory numOfPlace = new SubCategory
         {
             Id = sub,
             NumberOfPlace = places.Where(p => p.SubCategoryId == sub).Count()
         };
         numOfPlaces.Add(numOfPlace);
     }
     return Json(new { success = true, results = places, nums = numOfPlaces });
 }