public ActionResult GetImagesAll(string value) { if (value == null) { ViewBag.Reason = String.Format("{ 0}.", Resources.Translations.YouDidNotEnterAnything);; return(View("Error")); } string searchingValue = value.Trim(); int hitsLimit = 100; var postcardWithNames = PostcardSearcher.Search(value, "Name", hitsLimit). ToList(); if (postcardWithNames.Count >= hitsLimit) { return(View(postcardWithNames)); } PostcardComparer comparer = new PostcardComparer(); var postcardWithHastTag = GetPostcardsWithTag(searchingValue); var postcardWithComments = GetPostcardsWithComments(searchingValue); var uniquePostcards = postcardWithHastTag.Union(postcardWithComments, comparer).Union(postcardWithNames, comparer); ViewBag.SearchingValue = value; return(View(uniquePostcards)); }
public JsonResult GetPostcardsPage(string userId, int?pageSize, int?postcardPage) { if (userId == null || pageSize == null || pageSize == 0 || postcardPage == null) { return(Json(null, JsonRequestBehavior.AllowGet)); } int postcardsToSkip = postcardPage.Value * pageSize.Value; var result = PostcardSearcher.Search(userId, "OwnerId").Skip(postcardsToSkip). Take(pageSize.Value).Select(p => new { databaseId = p.Id, imageUrl = p.ImageUrl, jsonPath = p.JsonPath, name = p.Name }); return(Json(result, JsonRequestBehavior.AllowGet)); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); ApplicationDbContext db = new ApplicationDbContext(); PostcardSearcher.ClearIndex(); PostcardSearcher.AddUpdateLuceneIndex(db.Postcards); HashTagSearcher.ClearIndex(); HashTagSearcher.AddUpdateLuceneIndex(db.HashTags); }
public JsonResult DeletePostcard(int?id) { if (id == null) { return(Json(new { success = false })); } ApplicationDbContext db = new ApplicationDbContext(); Postcard neededPostcard = db.Postcards.SingleOrDefault(p => p.Id == id); if (neededPostcard == null) { return(Json(new { success = false })); } PostcardSearcher.ClearIndexRecord(id.Value); db.Postcards.Remove(neededPostcard); db.SaveChanges(); return(Json(new { success = true })); }
public JsonResult SavePostcard(int?templateId, int?categoryId, string name, string hashTags, string imagePath, string imageUrl, string jsonPath) { if (templateId == null || categoryId == null || name == null || imageUrl == null || jsonPath == null) { return(Json(new { success = false })); } Postcard newPostcard = new Postcard { TemplateId = templateId, CategoryId = categoryId, Name = name, ImagePath = imagePath, ImageUrl = imageUrl, JsonPath = jsonPath, OwnerId = User.Identity.GetUserId() }; ApplicationDbContext db = new ApplicationDbContext(); db.Postcards.Add(newPostcard); db.SaveChanges(); PostcardSearcher.AddUpdateLuceneIndex(newPostcard); newPostcard.AddHashTags(hashTags); return(Json(new { success = true })); }