public ActionResult LikeArticle(int?id, Article model) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } using (var database = new BlogDBContext()) { var currentUserID = database.Users.First(u => u.UserName == this.User.Identity.Name).Id; var currentPostID = database.Articles.First(p => p.Id == id); if (!currentPostID.UsersLikesIDs.Contains(currentUserID)) { currentPostID.UsersLikesIDs += currentUserID; currentPostID.Score += 1; database.Entry(currentPostID).State = EntityState.Modified; database.SaveChanges(); this.AddNotification("Post liked!", NotificationType.SUCCESS); } return(RedirectToAction($"Details/{id}")); } }
public ActionResult Login(User input) { if (ModelState.IsValid) { using (BlogDBContext db = new BlogDBContext()) { var authUser = db.Members.Any(u => u.Username == input.Username && u.Password == input.Password); if (authUser) { var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, input.Username), }, DefaultAuthenticationTypes.ApplicationCookie, ClaimTypes.Name, ClaimTypes.Role); identity.AddClaim(new Claim(ClaimTypes.Role, "guest")); Authentication.SignIn(identity); return(RedirectToAction("index", "blogs")); } } } return(View("Login", input)); }
public ActionResult Query(comments model) { using (BlogDBContext _db = new BlogDBContext()) { var comments = _db.Collection <comments>(); #region Query Parameters var filterBuilder = Builders <comments> .Filter; var filter = filterBuilder.Empty; if (model != null) { if (!string.IsNullOrEmpty(model.name)) { filter = filter & filterBuilder.Eq(x => x.name, model.name); } if (!string.IsNullOrEmpty(model.comment)) { filter = filter & filterBuilder.Eq(x => x.comment, model.comment); } } #endregion var result = comments.Find(filter).ToList(); return(View("Index", result)); } }
public ActionResult ChnageProfilePicture() { //This works only if you are logged in if (User.Identity.IsAuthenticated) { // To convert the user uploaded Photo as Byte Array before save to DB byte[] imageData = null; if (Request.Files.Count > 0) { HttpPostedFileBase poImgFile = Request.Files["ProfilePicture"]; using (var binary = new BinaryReader(poImgFile.InputStream)) { imageData = binary.ReadBytes(poImgFile.ContentLength); } } var store = new UserStore <ApplicationUser>(new BlogDBContext()); var userManager = new UserManager <ApplicationUser>(store); ApplicationUser user = userManager.FindByNameAsync(User.Identity.Name).Result; var db = new BlogDBContext(); var u = db.Users.Find(user.Id); if (u != null) { u.ProfilePicture = imageData; db.SaveChanges(); } } return(RedirectToAction("Index", "Manage")); }
public ActionResult DeleteConfirmed(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } using (var db = new BlogDBContext()) { var user = db.Users.Where(u => u.Id.Equals(id)).First(); var userPosts = db.Articles.Where(a => a.AuthorId.Equals(user.Id)); var userComments = db.Comments.Where(c => c.AuthorId.Equals(user.Id)); foreach (var post in userPosts) { db.Articles.Remove(post); } foreach (var comment in userComments) { db.Comments.Remove(comment); } db.Users.Remove(user); db.SaveChanges(); this.AddNotification("You have deleted the user!", NotificationType.SUCCESS); return(RedirectToAction("List")); } }
private void CreateUser(string email, string fullName, string password, BlogDBContext context) { var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); userManager.PasswordValidator = new PasswordValidator() { RequireDigit = false, RequiredLength = 4, RequireLowercase = false, RequireNonLetterOrDigit = false, RequireUppercase = false }; var user = new ApplicationUser() { Email = email, FullName = fullName, UserName = email }; // Setting the password from the UserManager rather than storing it in the db as plain string var result = userManager.Create(user, password); if (!result.Succeeded) { throw new Exception(string.Join(";", result.Errors)); } }
/// <summary> /// Премахваме банда. /// </summary> public static void RemoveBand(string bandName) { var context = new BlogDBContext(); var band = context.Bands.FirstOrDefault(f => f.Name == bandName); // Ако бандата вече я няма се връщаме. if (band is null) { return; } // Взимаме всички песни от бандата и ги махаме от албумите и плейлистите също. var bandSongs = context.BandsSongs.ToArray().Where(w => w.BandID == band.ID).ToArray(); var songs = context.Songs.ToArray().Where(w => bandSongs.FirstOrDefault(f => f.SongID == w.ID) != null); var albumSongs = context.AlbumsSongs.ToArray().Where(w => songs.FirstOrDefault(f => f.ID == w.SongID) != null); var playListSongs = context.PlayListsSongs.ToArray().Where(w => songs.FirstOrDefault(f => f.ID == w.SongID) != null); context.BandsSongs.RemoveRange(bandSongs); context.AlbumsSongs.RemoveRange(albumSongs); context.PlayListsSongs.RemoveRange(playListSongs); context.SaveChanges(); CheckIfEmpty(context); context.Songs.RemoveRange(songs); context.SaveChanges(); SetCollection(); RefreshDataBase(); }
/// <summary> /// Премахваме плейлист. /// </summary> public static void RemovePlayList(string name) { var context = new BlogDBContext(); var playList = context.PlayLists.FirstOrDefault(f => f.Name == name); // Ако плейлиста не съществува се връщаме. if (playList is null) { return; } // Взимаме всички песни от плейлиста и ги махаме от него. var playListSongs = context.PlayListsSongs.Where(w => w.PlayListID == playList.ID); context.PlayListsSongs.RemoveRange(playListSongs); context.PlayLists.Remove(playList); context.SaveChanges(); var colPlayList = Collection.PlayLists.FirstOrDefault(f => f.Name == name); if (colPlayList != null) { Collection.PlayLists.Remove(colPlayList); } // Обновяваме листа с плейлистите. PlayList.OnPropertyChanged("PlayList"); }
public static Post Get(int Postid) { using (BlogDBContext db = new BlogDBContext()) { return(db.Post.Include("Tags").FirstOrDefault(p => p.PostID == Postid)); } }
private void CreateUser(BlogDBContext context, string email, string fullName, string password) { // create user manager var userManager = new UserManager <ApplicationUser>( new UserStore <ApplicationUser>(context)); // set user manager password validator userManager.PasswordValidator = new PasswordValidator() { RequiredLength = 1, RequireDigit = false, RequireLowercase = false, RequireNonLetterOrDigit = false, RequireUppercase = false, }; // create user object var admin = new ApplicationUser { UserName = email, FullName = fullName, Email = email, }; // create user var result = userManager.Create(admin, password); if (!result.Succeeded) { throw new Exception(string.Join(";", result.Errors)); } }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } using (var database = new BlogDBContext()) { var conference = database.Events .Where(n => n.Id == id) .First(); if (conference == null) { return(HttpNotFound()); } var model = new EventViewModel(); model.Id = conference.Id; model.Title = conference.Title; model.Content = conference.Content; model.Date = conference.Date; return(View(model)); } }
static void Main(string[] args) { using (var db = new BlogDBContext()) { // Nhập tên 1 Blog mới cần tạo Console.Write("Ten cua 1 Blog moi: "); var name = Console.ReadLine(); // Thêm 1 Blog mới var blog = new Blog { Name = name }; db.Blog.Add(blog); db.SaveChanges(); // Hiển thị các Blog trong database, sắp xếp theo Name var query = from b in db.Blog orderby b.Name select b; Console.WriteLine("Tat ca blog trong database -- dammio.com:"); foreach (var item in query) { Console.WriteLine(item.Name); } Console.WriteLine("Go bat ky phim nao de thoat..."); Console.ReadKey(); } }
public ActionResult Edit(ArticleViewModel model) { // check if model state is valid if (ModelState.IsValid) { using (var database = new BlogDBContext()) { // get the article from db var article = database.Articles.FirstOrDefault(a => a.Id == model.Id); // set article properties article.Title = model.Title; article.Content = model.Content; article.CategoryId = model.CategoryId; this.SetArticleTags(article, model, database); // set article state database.Entry(article).State = EntityState.Modified; database.SaveChanges(); // redirect to index page return(RedirectToAction("ListCategories", "Home")); } } // if not valid return same view return(View(model)); }
public ActionResult Create(ArticleViewModel model) { if (ModelState.IsValid) { // Insert article in DB using (var database = new BlogDBContext()) { var authorId = database.Users .Where(u => u.UserName == this.User.Identity.Name) .First() .Id; var article = new Article(authorId, model.Title, model.Content, model.CategoryId); this.SetArticleTags(article, model, database); database.Articles.Add(article); database.SaveChanges(); return(RedirectToAction("ListCategories", "Home")); } } return(View(model)); }
public ActionResult DeleteConfirmed(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } using (var database = new BlogDBContext()) { // get article from the db var article = database.Articles .Where(a => a.Id == id) .Include(a => a.Author) .First(); // check if article exists if (article == null) { return(HttpNotFound()); } // remove article form DB database.Articles.Remove(article); database.SaveChanges(); // redirect to Index page return(RedirectToAction("ListCategories", "Home")); } }
// Get public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } using (var database = new BlogDBContext()) { // get article fron the database var article = database.Articles .Where(a => a.Id == id) .Include(a => a.Author) .Include(a => a.Category) .First(); if (!IsUserAuthorizedToEdit(article)) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } ViewBag.TagsString = string.Join(", ", article.Tags.Select(t => t.Name)); // check if article exists if (article == null) { return(HttpNotFound()); } // pass article to view return(View(article)); } }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } using (var database = new BlogDBContext()) { var article = database.Articles .Where(a => a.Id == id) .Include(a => a.Author) .Include(c => c.Category) .First(); if (!IsUserAuthorizedToEdit(article)) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } if (article == null) { return(HttpNotFound()); } this.AddNotification("Article will be deleted.", NotificationType.WARNING); return(View(article)); } }
public ActionResult Edit(string id, EditUserViewModel viewModel) { if (ModelState.IsValid) { using (var database = new BlogDBContext()) { //Get user from database var user = database.Users.FirstOrDefault(u => u.Id == id); //Check if user exists if (user == null) { return(HttpNotFound()); } //If password field is not empty, change password if (!string.IsNullOrEmpty(viewModel.Password)) { this.ChangeUserPassword(id, viewModel); } //Set user roles this.SetUserRoles(viewModel, user, database); //Save changes database.Entry(user).State = EntityState.Modified; database.SaveChanges(); return(RedirectToAction("List")); } } return(View(viewModel)); }
public static Admin Get(Admin admin) { using (BlogDBContext db = new BlogDBContext()) { return(db.Admin.FirstOrDefault(a => a.UserName == admin.UserName && a.Password == admin.Password)); } }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } using (var database = new BlogDBContext()) { var article = database.Articles.Where(a => a.Id == id).First(); if (!IsUserAuthorizedToEdit(article)) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } if (article == null) { return(HttpNotFound()); } this.AddNotification("Article will be edited.", NotificationType.WARNING); var model = new ArticleViewModel(); model.Id = article.Id; model.Title = article.Title; model.Content = article.Content; model.CategoryId = article.CategoryId; model.Categories = database.Categories.OrderBy(c => c.Name).ToList(); return(View(model)); } }
/// <summary> /// Добавяме песни към плейлист. /// </summary> public static void AddSongsToPlayList(string name, Song[] songs) { var context = new BlogDBContext(); var playListEF = context.PlayLists.FirstOrDefault(f => f.Name == name); // Ако плейлиста не съществува се връщаме. if (playListEF is null) { return; } // Добавяме тези песни, които вече не са в плейлиста към него. var addSongs = songs.Select(s => new PlayListSongsEF { PlayListID = playListEF.ID, SongID = s.ID }); addSongs = addSongs.Where(w => context.PlayListsSongs.FirstOrDefault(f => f.PlayListID == playListEF.ID && f.SongID == w.SongID) is null); context.PlayListsSongs.AddRange(addSongs); context.SaveChanges(); // Взимаме плейлиста и го обновяваме. var playList = Collection.PlayLists.FirstOrDefault(f => f.Name == name); playList.Songs.AddRange(songs.Where(w => playList.Songs.FirstOrDefault(f => f.ID == w.ID) is null)); PlayList.OnPropertyChanged("PlayList"); }
public static List <Post> GetALLRating() { using (BlogDBContext db = new BlogDBContext()) { return(db.Post.OrderByDescending(p => p.PostDate).ToList()); } }
/// <summary> /// Взимаме песента използвайки нейното име. /// </summary> public static Song[] GetSongFromName(string name) { var context = new BlogDBContext(); var song = context.Songs.FirstOrDefault(f => f.Name == name); return(song is null ? null : (new[] { song })); }
public static void Add(Post post) { using (BlogDBContext db = new BlogDBContext()) { foreach (var itemTag in post.Tags) { var result = db.Tag.Include("Posts").FirstOrDefault(t => t.Name == itemTag.Name); if (result != null) { post.Tags = null; result.Posts.Add(post); } else { itemTag.Posts = new List <Post>() { post }; db.Tag.Add(itemTag); } } db.SaveChanges(); } }
//GET: User/Edit public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } using (var db = new BlogDBContext()) { var user = db.Users.Where(u => u.Id == id).First(); if (user == null) { return(HttpNotFound()); } //create a view model var viewModel = new EditUserViewModel(); viewModel.User = user; viewModel.Roles = GetUserRoles(user, db); this.AddNotification("You are about to edit the user!", NotificationType.WARNING); return(View(viewModel)); } }
public ActionResult LikeComment(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } using (var db = new BlogDBContext()) { var currentUserID = db.Users.First(u => u.UserName == this.User.Identity.Name).Id; var currentCommentID = db.Comments.First(c => c.Id == id); var TextPostId = currentCommentID.ArticleId; if (!currentCommentID.UsersLikesIDs.Contains(currentUserID)) { currentCommentID.UsersLikesIDs += currentUserID; currentCommentID.Score += 1; db.SaveChanges(); this.AddNotification("Comment liked!", NotificationType.SUCCESS); } return(RedirectToAction("Details", "Article", new { id = TextPostId })); } }
public ActionResult DeleteConfirmed(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } using (var database = new BlogDBContext()) { // get user from database var user = database.Users .Where(u => u.Id.Equals(id)) .First(); // get user articles from the database var userArticles = database.Articles .Where(a => a.Author.Id.Equals(user.Id)); // delete user articles foreach (var article in userArticles) { database.Articles.Remove(article); } // delete user and save changes database.Users.Remove(user); database.SaveChanges(); return(RedirectToAction("List")); } }
private List <Role> GetUserRoles(ApplicationUser user, BlogDBContext database) { // create user manager var userManager = Request .GetOwinContext() .GetUserManager <ApplicationUserManager>(); // get all application roles var roles = database.Roles .Select(r => r.Name) .OrderBy(r => r) .ToList(); // for each application role, check if the user has it var userRoles = new List <Role>(); foreach (var roleName in roles) { var role = new Role { Name = roleName }; if (userManager.IsInRole(user.Id, roleName)) { role.IsSelected = true; } userRoles.Add(role); } // return a list with all roles return(userRoles); }
// get user/edit public ActionResult Edit(string id) { // validate id if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } using (var database = new BlogDBContext()) { // get user from db var user = database.Users .Where(u => u.Id == id) .First(); // check if user exists if (user == null) { return(HttpNotFound()); } // create a view model var viewModel = new EditUserViewModel(); viewModel.User = user; viewModel.Roles = GetUserRoles(user, database); // pass the model to the view return(View(viewModel)); } }
public static List <Post> GetAll() { using (BlogDBContext db = new BlogDBContext()) { return(db.Post.Where(p => p.IsDeleted == false).OrderByDescending(p => p.PostDate).ToList()); } }
public ActionResult AdvancedFanSearch(string firstName, string lastName, DateTime birthDate) { using (BlogDBContext context = new BlogDBContext()) { List<Fan> fans = context.Fans.Where(u => u.FirstName == firstName && u.LastName == lastName && u.BirthDate.CompareTo(birthDate) == 0).ToList<Fan>(); return View("FanSearchResult", fans); } }
public ActionResult EditFan(int id) { using (BlogDBContext context = new BlogDBContext()) { Fan currFan = context.Fans.Where(u => u.ID == id).FirstOrDefault<Fan>(); return View(currFan); } }
// // GET: /FanClub/ public ActionResult Index() { using (BlogDBContext context = new BlogDBContext()) { Fan[] fans = context.Fans.OrderBy(u => u.ID).ToArray<Fan>(); return View(fans); } }
public ActionResult Details(int id) { using (BlogDBContext context = new BlogDBContext()) { Post currPost = context.Posts.Where(u => u.ID == id).FirstOrDefault<Post>(); currPost.Comments = context.Comments.Where(u => u.PostID == currPost.ID).ToList<Comment>(); return View(currPost); } }
public ActionResult DeleteComment(int id) { using (BlogDBContext context = new BlogDBContext()) { Comment toDelete = context.Comments.Where(u => u.ID == id).FirstOrDefault<Comment>(); context.Comments.Remove(toDelete); context.SaveChanges(); } return RedirectToAction("Index"); }
public ActionResult AddComment(int id,string title,string author,string siteurl,string content) { using (BlogDBContext context = new BlogDBContext()) { Post relatedPost = context.Posts.Where(u => u.ID == id).FirstOrDefault<Post>(); Comment comment = new Comment(title, author, siteurl, content, relatedPost); context.Comments.Add(comment); context.SaveChanges(); } return RedirectToAction("Index"); }
public ActionResult Create(string firstName, string lastName, bool gender, DateTime dateOfBirth, int timeInClub) { using (BlogDBContext context = new BlogDBContext()) { //int maxId = context.Fans.OrderBy(u => u.ID).Max().ID; Fan newFan = new Fan(firstName, lastName, gender, dateOfBirth, timeInClub); //context.Entry(newFan).State = System.Data.Entity.EntityState.Added; context.Fans.Add(newFan); context.SaveChanges(); return RedirectToAction("Index"); } }
// // GET: /Blog/ public ActionResult Index() { using (BlogDBContext context = new BlogDBContext()) { List<Post> posts = context.Posts.OrderBy(u => u.ID).ToList<Post>(); for (int index = 0; index < posts.Count; index++) { Post currPost = posts[index]; posts[index].Comments = context.Comments.Where(u => u.PostID == currPost.ID).ToList<Comment>(); } return View(posts); } }
public ActionResult AdvancedSearchPost(string titleSearchPost, string authorNameSearchPost, DateTime fromDateSearchPost, DateTime toDateSearchPost) { using (BlogDBContext context = new BlogDBContext()) { List<Post> searchResult = context.Posts.Where(u => u.Author.Contains(authorNameSearchPost) && u.Title.Contains(titleSearchPost) && u.PostDate.CompareTo(fromDateSearchPost) >= 0 && u.PostDate.CompareTo(toDateSearchPost) <= 0).ToList<Post>(); for (var i = 0; i < searchResult.Count; i++) { Post current = searchResult[i]; current.Comments = context.Comments.Where(u => u.PostID == current.ID).ToList<Comment>(); } return PartialView("PostsListPartialView", searchResult); } }
public ActionResult Create(string title, string author, string siteurl, string content, HttpPostedFileBase uploadedImage, string uploadedVideo) { using (BlogDBContext context = new BlogDBContext()) { byte[] image = null; MemoryStream target; if (uploadedImage != null) { target = new MemoryStream(); uploadedImage.InputStream.CopyTo(target); image = target.ToArray(); } Post newPost = new Post(author, title, siteurl, content, image, uploadedVideo); context.Posts.Add(newPost); context.SaveChanges(); return RedirectToAction("Index"); } }
public ActionResult SearchCommentsByContent(string commentContent) { using (BlogDBContext context = new BlogDBContext()) { List<Comment> comments = context.Comments.Where(u => u.CommentText.Contains(commentContent) == true).ToList<Comment>(); return View("CommentsSearchResult", comments); } }
public ActionResult SearchFanByFirstName(string fanNameSearch) { using (BlogDBContext context = new BlogDBContext()) { List<Fan> fans = context.Fans.Where(u => u.FirstName == fanNameSearch).ToList<Fan>(); return View("FanSearchResult", fans); } }
public ActionResult SearchFanByMinYears(int fanYearsSearch) { using (BlogDBContext context = new BlogDBContext()) { List<Fan> fans = context.Fans.Where(u => u.TimeInClub >= fanYearsSearch).ToList<Fan>(); return View("FanSearchResult", fans); } }
// // GET: /Manager/ public ActionResult Index() { using (BlogDBContext context = new BlogDBContext()) { Post[] posts = context.Posts.OrderBy(u => u.ID).ToArray<Post>(); for (int index = 0; index < posts.Length; index++) { Post currPost = posts[index]; posts[index].Comments = context.Comments.Where(u => u.PostID == currPost.ID).ToList<Comment>(); } Dictionary<string, int> statistics = context.Posts.GroupBy(x => new { x.PostDate.Year, x.PostDate.Month, x.PostDate.Day }) .Select(g=>new {Key = g.Key, Count=g.Count()}) .OrderBy(x=>x.Key.Year) .ThenBy(x=>x.Key.Month) .ThenBy(x=>x.Key.Day) .ToDictionary(p => (p.Key.Day.ToString() + "/" + p.Key.Month.ToString() + "/" + p.Key.Year.ToString()),h=>h.Count); PostsStatistics model = new PostsStatistics(); model.Posts = posts; model.Statistics = statistics; return View(model); } }
public ActionResult SearchCommentsByAuthor(string authorNameSearchComment) { using (BlogDBContext context = new BlogDBContext()) { List<Comment> comments = context.Comments.Where(u => u.Author == authorNameSearchComment).ToList<Comment>(); return View("CommentsSearchResult", comments); } }
public ActionResult SearchPostByCommentContainText(string commentText) { using (BlogDBContext context = new BlogDBContext()) { List<Post> searchResult = context.Posts.Join(context.Comments, p => p.ID, c => c.PostID, (p, c) => new { Post = p, Comment = c }).Where(u => u.Comment.CommentText.Contains(commentText)).Select(x => x.Post).ToList<Post>(); for (var i = 0; i < searchResult.Count; i++) { Post current = searchResult[i]; current.Comments = context.Comments.Where(u => u.PostID == current.ID).ToList<Comment>(); } return View("PostSearchResult", searchResult); } }
public ActionResult SearchPostByDate(DateTime fromDateSearchPost, DateTime toDateSearchPost) { using (BlogDBContext context = new BlogDBContext()) { List<Post> posts = context.Posts.Where(u => u.PostDate.CompareTo(fromDateSearchPost) >= 0 && u.PostDate.CompareTo(toDateSearchPost) <= 0).ToList<Post>(); for (var i = 0; i < posts.Count; i++) { Post current = posts[i]; current.Comments = context.Comments.Where(u => u.PostID == current.ID).ToList<Comment>(); } return View("PostSearchResult",posts); } }
public ActionResult Update(int id, string title, string author, string siteurl, string content, HttpPostedFileBase uploadedImage, string uploadedVideo) { using (BlogDBContext context = new BlogDBContext()) { byte[] image = null; MemoryStream target; if (uploadedImage != null) { target = new MemoryStream(); uploadedImage.InputStream.CopyTo(target); image = target.ToArray(); } Post newPost = new Post(author, title, siteurl, content, image, uploadedVideo); Post currPost = context.Posts.Where(u => u.ID == id).FirstOrDefault<Post>(); currPost.Author = newPost.Author; currPost.Comments = newPost.Comments; currPost.Content = newPost.Content; currPost.Image = newPost.Image; currPost.PostDate = newPost.PostDate; currPost.SiteUrl = newPost.SiteUrl; currPost.Title = newPost.Title; currPost.Video = newPost.Video; context.SaveChanges(); return RedirectToAction("Index"); } }
public ActionResult UpdateComment(int id, string content) { using (BlogDBContext context = new BlogDBContext()) { Comment toEdit = context.Comments.Where(u => u.ID == id).FirstOrDefault<Comment>(); toEdit.CommentText = content; context.SaveChanges(); return RedirectToAction("Index"); } }
public ActionResult Edit(int id) { using (BlogDBContext context = new BlogDBContext()) { Post currPost = context.Posts.Where(u => u.ID == id).FirstOrDefault<Post>(); return View(currPost); } }
public ActionResult EditComment(int id) { using (BlogDBContext context = new BlogDBContext()) { Comment currComment = context.Comments.Where(u => u.ID == id).FirstOrDefault<Comment>(); return View(currComment); } }
public ActionResult SearchPostByAuthor(string authorNameSearchPost) { using (BlogDBContext context = new BlogDBContext()) { List<Post> posts = context.Posts.Where(u => u.Author == authorNameSearchPost).ToList<Post>(); for (var i = 0; i < posts.Count; i++) { Post current = posts[i]; current.Comments = context.Comments.Where(u => u.PostID == current.ID).ToList<Comment>(); } return View("PostSearchResult", posts); } }
public ActionResult Update(int id, string firstName, string lastName, bool gender, DateTime dateOfBirth, int timeInClub) { using (BlogDBContext context = new BlogDBContext()) { Fan currFan = context.Fans.Where(u => u.ID == id).FirstOrDefault<Fan>(); currFan.FirstName = firstName; currFan.LastName = lastName; currFan.Gender = gender; currFan.BirthDate = dateOfBirth; currFan.TimeInClub = timeInClub; context.SaveChanges(); } return RedirectToAction("Index"); }