コード例 #1
0
 public ActionResult Index(string r)
 {
     SearchViewModel model = new SearchViewModel();
     if (r == null || r.Length == 0)
         return View(model);
     List<Demotivator> demotivatorList = new List<Demotivator>();
     List<ApplicationUser> userList = new List<ApplicationUser>();
     using (var elastic = new elasticsearchNEST())
     {
         var demotivators = elastic.SearchDemotivators(r);
         var users = elastic.SearchUser(r);
         if (demotivators.Count() != 0) {
             foreach (var dem in demotivators) {
                 demotivatorList.Add(dem);
             }
         }
         if (users.Count() != 0) {
             foreach (var user in users)
             {
                 userList.Add(user);
             }
         }
     }
     model.demotivators = demotivatorList;
     model.User = userList;
     return View(model);
 }
コード例 #2
0
 public JsonResult Search(string term)
 {
     List<string> jsonka = new List<string>();
     using (var elastic = new elasticsearchNEST())
     {
         var resultDem = elastic.SearchDemotivators(term);
         var resultUser = elastic.SearchUser(term);
         foreach (var user in resultUser)
         {
             jsonka.Add(user.UserName);
         }
         foreach (var dem in resultDem) {
             jsonka.Add(dem.Name);
         }
     }
     jsonka = jsonka.Distinct().ToList();
     return Json(jsonka, JsonRequestBehavior.AllowGet);
 }
コード例 #3
0
        public async Task<ActionResult> DeleteConfirmed(int id)
        {
            Demotivator demotivator = await db.Demotivators.FindAsync(id);
            if(User.Identity.GetUserId() != demotivator.AspNetUserId)
            {
                return RedirectToAction("Index", "Home");
            }
            DeleteAdds(id);

 using (var elastic = new elasticsearchNEST())
            {
                elastic.DeleteDem(demotivator);
            }
                db.Demotivators.Remove(demotivator);

            await db.SaveChangesAsync();
            return RedirectToAction("Index");
        }
コード例 #4
0
 public ActionResult Create([Bind(Include = "JSON,Id,AspNetUserId,Name,Date,Url_Img,Url_Img_Origin,Str1,Str2")] Demotivator demotivator, string newtag)
 {
     if (ModelState.IsValid)
     {
         demotivator.AspNetUserId = User.Identity.GetUserId();
         demotivator.Date = DateTime.Now;
         db.Demotivators.Add(demotivator);
         db.SaveChanges();
         using (var elastic = new elasticsearchNEST())
         {
             elastic.Adding(demotivator);
         }
         AddTag(newtag, demotivator.Id);
         return RedirectToAction("Index");
     }
     ViewBag.AspNetUserId = new SelectList(db.AspNetUsers, "Id", "Email", demotivator.AspNetUserId);
     return View(demotivator);
 }
コード例 #5
0
 public async Task<ActionResult> Register(RegisterViewModel model)
 {
     if (ModelState.IsValid)
     {
         var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
             var result = await UserManager.CreateAsync(user, model.Password);
         using (var elastic = new elasticsearchNEST())
         {
             elastic.Adding(user);
         }
         if (result.Succeeded)
         {
             var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
             var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code },
                        protocol: Request.Url.Scheme);
             await UserManager.SendEmailAsync(user.Id, Resources.Resource.MailTheme,
                        Resources.Resource.MailMessage + " <a href=\"" + callbackUrl + "\">here</a>");
             return View("DisplayEmail");
         }
         AddErrors(result);
     }
     return View(model);
 }