public async Task <IActionResult> Create([Bind("IDBlog,TieuDe,HinhAnh,TomTat,NoiDung,IDLoai,IDNguoiTao,NgayTao,NgayDuyet,View,IDNguoiDuyet,TrangThai")] CauHoi cauhoi, IFormFile ful) { if (ModelState.IsValid) { _context.Add(cauhoi); await _context.SaveChangesAsync(); var parth = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/cauhoi", cauhoi.IDBlog + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]); using (var stream = new FileStream(parth, FileMode.Create)) { await ful.CopyToAsync(stream); } cauhoi.HinhAnh = cauhoi.IDBlog + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]; _context.Update(cauhoi); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IDLoai"] = new SelectList(_context.Loais, "IDLoai", "TieuDe", cauhoi.IDLoai); return(View(cauhoi)); }
public async Task <IActionResult> Edit(int id, [Bind("IDBL,IDTK,IDBV,NgayTao,NoiDung,TrangThai")] BinhLuan binhLuan) { if (id != binhLuan.IDBL) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(binhLuan); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BinhLuanExists(binhLuan.IDBL)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["IDTK"] = new SelectList(_context.TaiKhoans, "IDTK", "IDTK", binhLuan.IDTK); return(View(binhLuan)); }
public async Task <int> DeleteAsync(int id) { var category = _context.Category.FirstOrDefault(x => x.Id == id); if (category != null) { category.Status = category.Status ? false : true; _context.Update(category); return(await _context.SaveChangesAsync()); } return(-1); }
public async Task <IActionResult> Edit(int id, [Bind("IDLoai,TieuDe,NgayTao,IDNguoiTao")] Loai loai) { if (id != loai.IDLoai) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(loai); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LoaiExists(loai.IDLoai)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(loai)); }
public async Task <IActionResult> Edit(int id, [Bind("IDBlog,TieuDe,HinhAnh,TomTat,NoiDung,IDLoai,IDNguoiTao,NgayTao,NgayDuyet,View,IDNguoiDuyet,TrangThai")] CauHoi cauHoi) { if (id != cauHoi.IDBlog) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(cauHoi); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CauHoiExists(cauHoi.IDBlog)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["IDLoai"] = new SelectList(_context.Loais, "IDLoai", "IDLoai", cauHoi.IDLoai); return(View(cauHoi)); }
public async Task <int> UpdateAvartar(int userId, string img) { var finNotification = GetAll().Where(x => x.UserId == userId); if (finNotification.Count() > 0) { foreach (var item in finNotification) { item.AvartarUser = img; item.LoginExternal = false; _context.Update(item); } return(await _context.SaveChangesAsync()); } return(0); }
public async Task <IActionResult> Edit(int id, [Bind("IDTK,Ten,Password,HinhAnh,Quyen,TrangThai")] TaiKhoan taiKhoan) { if (id != taiKhoan.IDTK) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(taiKhoan); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TaiKhoanExists(taiKhoan.IDTK)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(taiKhoan)); }
public async Task <int> Update(CommentRequest cmRequest) { var comment = _context.Comment.FirstOrDefault(X => X.Id == cmRequest.Id); if (cmRequest != null) { comment.Content = cmRequest.Content; comment.UserId = cmRequest.UserId; comment.CommentId = cmRequest.CommentId; comment.VideoId = cmRequest.VideoId; comment.Like = cmRequest.Like; comment.DisLike = cmRequest.DisLike; _context.Update(comment); return(await _context.SaveChangesAsync()); } return(0); }
public async Task <int> Update(PlaylistRequest plRequest) { var playlist = _context.PlayList.FirstOrDefault(X => X.Id == plRequest.Id); if (playlist != null) { playlist.Name = plRequest.Name; _context.Update(playlist); return(await _context.SaveChangesAsync()); } return(-1); }
public async Task <int> UpdateNotifi(FollowChannelRequest request) { var follow = _contex.FollowChannel.FirstOrDefault(X => X.FromUserId == request.FromUserId && X.ToUserId == request.ToUserId); if (follow != null) { follow.Notifications = false; _contex.Update(follow); return(await _contex.SaveChangesAsync()); } return(-1); }
public async Task <IActionResult> Create([Bind("IDTK,Ten,Password,HinhAnh,Quyen,TrangThai")] TaiKhoan taiKhoan, IFormFile ful) { if (ModelState.IsValid) { _context.Add(taiKhoan); await _context.SaveChangesAsync(); var parth = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/Admin/avatar", taiKhoan.IDTK + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]); using (var stream = new FileStream(parth, FileMode.Create)) { await ful.CopyToAsync(stream); } taiKhoan.HinhAnh = taiKhoan.IDTK + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]; _context.Update(taiKhoan); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(taiKhoan)); }
public async Task <int> Update(MessageRequest request) { var message = GetAll().FirstOrDefault(X => X.Id == request.Id); if (message != null) { message.Content = request.Content; _context.Update(message); return(await _context.SaveChangesAsync()); } return(-1); }
public async Task <int> Update(LikeVideoRequest likeRequest) { var like = _context.LikeVideoDetail.FirstOrDefault(X => X.Id == likeRequest.Id); if (likeRequest != null) { like.Reaction = likeRequest.Reaction; like.UserId = likeRequest.UserId; like.VideoId = likeRequest.VideoId; } _context.Update(like); return(await _context.SaveChangesAsync()); }
public async Task <Video> Create(VideoRequest videoRequest, List <IFormFile> listPost) { var video = new Video(); if (videoRequest != null) { video.Name = videoRequest.Name; video.Description = videoRequest.Description; video.AppUserId = videoRequest.AppUserId; video.CreateDate = new GetDateNow().DateNow; video.HidenVideo = videoRequest.HidenVideo; video.CategorysId = videoRequest.CategorysId; _context.Video.Add(video); _context.SaveChanges(); var findVideo = _context.Video.OrderByDescending(x => x.Id).FirstOrDefault(x => x.Name.Contains(videoRequest.Name)); if (listPost.Count > 0) { var paths = ""; foreach (var item in listPost) { var filename = item.FileName.Split('.'); var name = filename[filename.Length - 1].ToLower(); if (name.Contains("mp4")) { name = findVideo.Id.ToString() + "." + filename[filename.Length - 1].ToLower(); paths = "wwwroot/Client/video"; findVideo.LinkVideo = name; } else { name = findVideo.Id.ToString() + "." + filename[filename.Length - 1].ToLower(); findVideo.PosterImg = name; paths = "wwwroot/Client/imgPoster"; } using (var fileStream = new FileStream(Path.Combine(paths, name), FileMode.Create, FileAccess.Write)) { item.CopyTo(fileStream); } } _context.Update(findVideo); await _context.SaveChangesAsync(); return(findVideo); } } return(null); }
public async Task <int> Delete(int id) { var user = _context.AppUser.Where(x => x.Status).FirstOrDefault(x => x.Id == id); if (user != null) { user.Status = false; _context.Update(user); return(await _context.SaveChangesAsync()); } return(-1); }