// GET: User/Blogs/Details/5 public async Task <IActionResult> Details(int?id) { i++; HttpContext.Session.SetString("view", i.ToString()); if (id == null) { return(NotFound()); } var blog = await _context.Blogs .Include(b => b.loai) .FirstOrDefaultAsync(m => m.IDBlog == id); blog.View = Int32.Parse(HttpContext.Session.GetString("view")); if (blog == null) { return(NotFound()); } await _context.SaveChangesAsync(); ViewBag.Loai = _context.Loais; return(View(blog)); }
public async Task <IActionResult> PutBlog(int id, Blog blog) { if (id != blog.IDBlog) { return(BadRequest()); } _context.Entry(blog).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BlogExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <PlayList> Create(PlaylistRequest plRequest) { var playlist = new PlayList(); if (plRequest != null) { PlayList checkName = new PlayList(); foreach (var item in GetAll().Where(x => x.UserId == plRequest.UserId)) { if (ConvertUnSigned.convertToUnSign(item.Name.ToLower()).Contains(ConvertUnSigned.convertToUnSign(plRequest.Name.ToLower()))) { checkName = item; break; } } if (checkName.Name == null) { playlist.Name = plRequest.Name; playlist.Status = plRequest.Status; playlist.UserId = plRequest.UserId; playlist.CreateDate = new GetDateNow().DateNow; _context.PlayList.Add(playlist); await _context.SaveChangesAsync(); var getPlaylist = _context.PlayList.OrderByDescending(x => x.Id). FirstOrDefault(x => x.Name == plRequest.Name && x.UserId == plRequest.UserId); return(getPlaylist); } } return(null); }
public async Task <int> CreateAsync(CategoryRequest categoryRequest) { var category = new Category(); category.Name = categoryRequest.Name; category.CreateDate = new GetDateNow().DateNow; _context.Category.Add(category); return(await _context.SaveChangesAsync()); }
public async Task <int> Create(FollowChannelRequest request) { var flChannel = new FollowChannel(); flChannel.FromUserId = request.FromUserId; flChannel.ToUserId = request.ToUserId; flChannel.Notifications = true; _contex.FollowChannel.Add(flChannel); return(await _contex.SaveChangesAsync()); }
public async Task <IActionResult> Create([Bind("IDLoai,TieuDe,NgayTao,IDNguoiTao")] Loai loai) { if (ModelState.IsValid) { _context.Add(loai); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(loai)); }
public async Task <IActionResult> Create([Bind("IDBL,IDTK,IDBV,IDCH,NgayTao,NoiDung,TrangThai")] BinhLuan binhLuan) { if (ModelState.IsValid) { _context.Add(binhLuan); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IDTK"] = new SelectList(_context.TaiKhoans, "IDTK", "IDTK", binhLuan.IDTK); return(View(binhLuan)); }
public async Task <IActionResult> Create([Bind("IDBlog,TieuDe,HinhAnh,TomTat,NoiDung,IDLoai,IDNguoiTao,NgayTao,NgayDuyet,View,IDNguoiDuyet,TrangThai")] CauHoi cauHoi) { if (ModelState.IsValid) { _context.Add(cauHoi); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IDLoai"] = new SelectList(_context.Loais, "IDLoai", "IDLoai", cauHoi.IDLoai); return(View(cauHoi)); }
public async Task <IActionResult> Create([Bind("IDLoai,TieuDe,NgayTao,IDNguoiTao")] Loai loai) { if (ModelState.IsValid) { _context.Add(loai); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewBag.IDTK = _context.TaiKhoans; ViewData["IDTK"] = new SelectList(_context.TaiKhoans, "IDTK", "Ten"); return(View(loai)); }
public async Task <int> Create(LikeVideoRequest likeRequest) { var like = new LikeVideoDetail(); if (likeRequest != null) { like.Reaction = likeRequest.Reaction; like.UserId = likeRequest.UserId; like.VideoId = likeRequest.VideoId; } _context.LikeVideoDetail.Add(like); return(await _context.SaveChangesAsync()); }
public async Task <IActionResult> Create([Bind("IDBL,IDTK,IDBV,NgayTao,NoiDung,TrangThai")] BinhLuan binhLuan) { HttpContext.Session.SetString("idbaiviet", binhLuan.IDBV.ToString()); if (ModelState.IsValid) { _context.Add(binhLuan); await _context.SaveChangesAsync(); return(Redirect(Request.Headers["Referer"].ToString())); } ViewData["IDTK"] = new SelectList(_context.TaiKhoans, "IDTK", "IDTK", binhLuan.IDTK); return(View(binhLuan)); }
public async Task <IActionResult> Create([Bind("IDTK,Ten,Password,HinhAnh,Quyen,TrangThai")] TaiKhoan taiKhoan) { if (ModelState.IsValid) { taiKhoan.Password = StringProcess.CreateMD5Hash(taiKhoan.Password); _context.Add(taiKhoan); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(taiKhoan)); }
public async Task <int> Create(DetailVideoRequest request) { var playlist = _context.PlayList.FirstOrDefault(X => X.Id == request.PlayListId); var detail = new DetailVideo(); if (request != null && playlist != null) { detail.PlayListId = request.PlayListId; detail.VideoId = request.VideoId; _context.DetailVideo.Add(detail); return(await _context.SaveChangesAsync()); } return(-1); }
public async Task <int> Create(NotificationRequest request, int toUserId) { var listFollow = _context.FollowChannel.Where(x => x.ToUserId == toUserId).ToList(); if (request != null && listFollow.Count > 0) { foreach (var item in listFollow) { if (item.Notifications) { var notifi = new Notification(); notifi.AvartarUser = request.AvartarUser; notifi.UserId = request.UserId; notifi.FromUserId = item.FromUserId; notifi.LoginExternal = request.LoginExternal; notifi.PoterImg = request.PoterImg; notifi.Content = "đã tải lên:" + request.Content; notifi.VideoId = request.VideoId; notifi.Watched = true; notifi.CreateDate = new GetDateNow().DateNow; notifi.Status = request.Status; notifi.UserName = request.UserName; _context.Notification.Add(notifi); } } return(await _context.SaveChangesAsync()); } return(-1); }
public async Task <int> Create(ReportVideoRequest request) { var report = new ReportVideo(); if (request != null) { report.Content = request.Content; report.UserId = request.UserId; report.VideoId = request.VideoId; report.CreateDate = new GetDateNow().DateNow; _context.ReportVideo.Add(report); return(await _context.SaveChangesAsync()); } return(-1); }
public async Task <int> Create(LikeCommentRequest likeRequest) { var like = new LikeCommentDetail(); if (likeRequest != null) { like.Comment = likeRequest.IdComment; like.Reaction = likeRequest.Reaction; like.UserId = likeRequest.UserId; like.VideoId = likeRequest.VideoId; _context.LikeComments.Add(like); return(await _context.SaveChangesAsync()); } return(0); }
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> Create(VideoWatchedRequest request) { var watched = new VideoWatched(); if (request != null) { var checkWatched = _context.VideoWatched. FirstOrDefault(X => X.VideoId == request.VideoId && X.UserId == request.UserId); if (checkWatched == null) { watched.UserId = request.UserId; watched.VideoId = request.VideoId; _context.VideoWatched.Add(watched); return(await _context.SaveChangesAsync()); } } return(-1); }
public async Task DeleteAsync(int id) { using (var db = new DpContext()) { var entity = await db.TaskItems.FindAsync(id); entity.Deleted = true; await db.SaveChangesAsync(); } }
public async Task <int> CreateAsync(TEntity entity) { using (var db = new DpContext()) { db.Set <TEntity>().Add(entity); await db.SaveChangesAsync(); return(entity.Id); } }
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 UpdateAsync(TEntity entity) { using (var db = new DpContext()) { entity.ModifiedDateTime = DateTimeOffset.UtcNow; db.Set <TEntity>().Attach(entity); db.Entry(entity).State = EntityState.Modified; await db.SaveChangesAsync(); } }
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 <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/Admin/images", 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", "IDLoai", cauHoi.IDLoai); return(View(cauHoi)); }
// GET: User/CauHois/Details/5 public async Task <IActionResult> Details(int?id) { if (kq != 0) { id = idcauhoi; } if (HttpContext.Session.GetString("user") != null) { JObject us = JObject.Parse(HttpContext.Session.GetString("user")); HttpContext.Session.SetString("idcauhoi", id.ToString()); ViewBag.IDName = us.SelectToken("IDTK").ToString(); } if (id == null) { return(NotFound()); } var cauhoi = await _context.CauHois .Include(b => b.loai) .FirstOrDefaultAsync(m => m.IDBlog == id); cauhoi.View = cauhoi.View + 1; if (cauhoi == null) { return(NotFound()); } await _context.SaveChangesAsync(); ViewBag.Loai = _context.Loais; ViewBag.BinhLuanCH = _context.BinhLuanCHs; var tenngtao = from s in _context.BinhLuanCHs join r in _context.TaiKhoans on s.IDTK equals r.IDTK join w in _context.CauHois on s.IDCH equals w.IDBlog select new { r.Ten, r.HinhAnh }; foreach (var item in tenngtao) { ViewBag.ten = item.Ten.ToString(); ViewBag.hinh = item.HinhAnh.ToString(); } return(View(cauhoi)); }
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); }
public async Task <int> Create(CommentRequest cmRequest) { var comment = new Comment(); if (cmRequest != null) { comment.Content = cmRequest.Content; comment.CreateDate = new GetDateNow().DateNow; comment.UserId = cmRequest.UserId; comment.ReplyForId = cmRequest.ReplyForId; comment.CommentId = cmRequest.CommentId; comment.VideoId = cmRequest.VideoId; comment.ReplyFor = cmRequest.ReplyFor; _context.Comment.Add(comment); return(await _context.SaveChangesAsync()); } return(0); }