public async Task <IActionResult> PostSearchhistory([FromBody] Searchhistory searchhistory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Searchhistory.Add(searchhistory); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (SearchhistoryExists(searchhistory.Usid)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetSearchhistory", new { id = searchhistory.Usid }, searchhistory)); }
public async Task <IActionResult> PutSearchhistory([FromRoute] int id, [FromBody] Searchhistory searchhistory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != searchhistory.Usid) { return(BadRequest()); } _context.Entry(searchhistory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SearchhistoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
private SearchHistoryDto MapSearchElement(Searchhistory elem) { var dto = _mapper.Map <SearchHistoryDto>(elem); //dto.Url = Url.Link(nameof(), new { elem.Nconst }); return(dto); }
public async Task <IActionResult> Gettagsearch(int offset, string keyword) { if (!ModelState.IsValid) { return(BadRequest(new { status = "invalid", data = ModelState })); } var keys = _context.Tag.Where(x => x.Name.Contains(keyword)).Skip(offset).Take(10); var result = keys.Select(x => new { tag_id = x.TagId, name = x.Name, catid = x.CatId }); bool isLogin = false; int myid = -1; var auth = await HttpContext.AuthenticateAsync(); if (auth.Succeeded) { var claim = User.FindFirstValue("User"); if (int.TryParse(claim, out myid)) { isLogin = true; } } if (isLogin) { try { var v = await _context.Searchhistory.FirstOrDefaultAsync(x => x.Usid == myid && x.Content == keyword); if (v != null) { _context.Searchhistory.Remove(v); } v = new Searchhistory(); v.CreateTime = DateTime.Now; v.Content = keyword; v.Usid = myid; _context.Searchhistory.Add(v); await _context.SaveChangesAsync(); } catch { return(Ok(new { status = "Create history failed!", data = result })); } } return(Ok(new { status = "ok", data = result })); }
public async Task <IActionResult> Getvideosearch(int offset, string keyword) { if (!ModelState.IsValid) { return(BadRequest(new { status = "invalid", data = ModelState })); } var keys = _context.Video.Where(x => x.Description.Contains(keyword) || x.Title.Contains(keyword)).Skip(offset).Take(10); string baseUrl = Request.Scheme + "://" + Request.Host + "/"; var result = keys.Select(x => new { vid = x.Vid, title = x.Title, desc = x.Description, cover = baseUrl + "images/" + x.Cover, view_num = x.WatchNum, comment_num = x.IsBanned, upload_time = x.CreateTime.ToTimestamp(), url = baseUrl + "videos/" + x.Path, like_num = x.LikeNum, favorite_num = x.FavoriteNum, share_num = 0 }); bool isLogin = false; int myid = -1; var auth = await HttpContext.AuthenticateAsync(); if (auth.Succeeded) { var claim = User.FindFirstValue("User"); if (int.TryParse(claim, out myid)) { isLogin = true; } } if (isLogin) { try { var v = await _context.Searchhistory.FirstOrDefaultAsync(x => x.Usid == myid && x.Content == keyword); if (v != null) { _context.Searchhistory.Remove(v); } v = new Searchhistory(); v.CreateTime = DateTime.Now; v.Content = keyword; v.Usid = myid; _context.Searchhistory.Add(v); await _context.SaveChangesAsync(); } catch { return(Ok(new { status = "Create history failed!", data = result })); } } return(Ok(new { status = "ok", data = new { count = _context.Video.Where(x => x.Description.Contains(keyword) || x.Title.Contains(keyword)).Count(), result } })); }
public async Task <IActionResult> GetUsersearch(int page, string keyword, bool only_cat) { if (!ModelState.IsValid) { return(BadRequest(new { status = "invalid", data = ModelState })); } bool isLogin = false; int myid = -1; List <int> FollowList = new List <int>(); var auth = await HttpContext.AuthenticateAsync(); if (auth.Succeeded) { var claim = User.FindFirstValue("User"); if (int.TryParse(claim, out myid)) { isLogin = true; } } if (isLogin) { FollowList = await _context.Follow.Where(x => x.Usid == myid).Select(x => x.FollowUsid).ToListAsync(); } var keys = _context.Users.Where(x => (x.Signature.Contains(keyword) || x.Nickname.Contains(keyword)) && (x.CatId != null || !only_cat)).Skip(page).Take(10); string baseUrl = Request.Scheme + "://" + Request.Host + "/"; var result = keys.Select(x => new { usid = x.Usid, name = x.Nickname, desc = x.Signature, follow_num = x.FollowerNum, avatar = baseUrl + "images/" + x.Avatar, work_num = _context.Video.Where(y => y.Usid == x.Usid).Count(), ifollow = FollowList.Contains(x.Usid) ? 1 : 0 }); if (isLogin) { try { var v = await _context.Searchhistory.FirstOrDefaultAsync(x => x.Usid == myid && x.Content == keyword); if (v != null) { _context.Searchhistory.Remove(v); } v = new Searchhistory(); v.CreateTime = DateTime.Now; v.Content = keyword; v.Usid = myid; _context.Searchhistory.Add(v); await _context.SaveChangesAsync(); } catch { return(Ok(new { status = "Create history failed!", data = new { count = _context.Users.Where(x => (x.Signature.Contains(keyword) || x.Nickname.Contains(keyword)) && (x.CatId != null || !only_cat)).Count(), result } })); } } return(Ok(new { status = "ok", data = new { count = _context.Users.Where(x => (x.Signature.Contains(keyword) || x.Nickname.Contains(keyword)) && (x.CatId != null || !only_cat)).Count(), result } })); }