public ActionResult ListsAnnouncement() { ProjeContext db = new ProjeContext(); List <Announcement> announcement = db.Announcement.ToList(); return(View(announcement)); }
public ActionResult Setting() { ProjeContext db = new ProjeContext(); Setting setting = db.Settings.Where(x => x.Id == 1).FirstOrDefault(); List <SelectListItem> selectListItem = new List <SelectListItem>() { new SelectListItem() { Text = "Admin", Value = "Admin" }, new SelectListItem() { Text = "Company", Value = "Company" }, new SelectListItem() { Text = "Member", Value = "Member" } }.ToList(); ViewBag.Roles = selectListItem; return(View(setting)); }
public ActionResult EditUsers(int?user_id, User model, HttpPostedFileBase file) { if (user_id != 0 && model != null) { ProjeContext db = new ProjeContext(); User user = db.User.Where(x => x.UserId == user_id).FirstOrDefault(); user.Username = model.Username; user.Password = model.Password; user.Role = model.Role; if (file != null && file.ContentLength > 0) { var profilePicturePath = Server.MapPath(user.ProfilePhoto); if (System.IO.File.Exists(profilePicturePath)) { System.IO.File.Delete(profilePicturePath); } var newFileName = Guid.NewGuid() + System.IO.Path.GetExtension(file.FileName); var serverPath = Server.MapPath("/ProfilesPhotos"); var path = Path.Combine(serverPath, newFileName).Replace("\\", "/"); file.SaveAs(path); var userProfilePhotoPath = $@"/ProfilesPhotos/{newFileName}"; user.ProfilePhoto = userProfilePhotoPath; } db.SaveChanges(); return(RedirectToAction("ListUsers", "Home")); } return(RedirectToAction("NotFound", "Error")); }
public ActionResult ListUsers() { ProjeContext db = new ProjeContext(); List <User> user = db.User.ToList(); return(View(user)); }
public ActionResult CommentAdd() { ProjeContext db = new ProjeContext(); List <SelectListItem> selectListItems = (from posts in db.Post.ToList() select new SelectListItem() { Text = posts.PostTitle, Value = posts.PostId.ToString() }).ToList(); List <SelectListItem> selectListItems1 = (from users in db.User.ToList() select new SelectListItem() { Text = users.Username, Value = users.Username }).ToList(); ViewBag.Posts = selectListItems; ViewBag.Users = selectListItems1; return(View()); }
public ActionResult ListComments() { ProjeContext db = new ProjeContext(); List <Comment> comments = db.Comment.ToList(); return(View(comments)); }
public ActionResult Login() { if (string.IsNullOrEmpty(HttpContext.User.Identity.Name)) { FormsAuthentication.SignOut(); return(View()); } else { ProjeContext db = new ProjeContext(); var role = db.User.Where(x => x.Username == HttpContext.User.Identity.Name).FirstOrDefault(); if (role.Role == "Admin") { return(RedirectToAction("Panel", "Home")); } else if (role.Role == "Company") { return(RedirectToAction("CompanyPanel", "Home")); } else if (role.Role == "Member") { return(RedirectToAction("Index", "Home")); } return(View()); } }
public ActionResult DeleteAnnouncement(int announcement_id) { ProjeContext db = new ProjeContext(); Announcement announcement = db.Announcement.Where(x => x.AnnouncementId == announcement_id).FirstOrDefault(); return(View(announcement)); }
public ActionResult Login(User user) { ProjeContext db = new ProjeContext(); var u = db.User.FirstOrDefault(x => x.Username == user.Username && x.Password == user.Password); if (u != null) { FormsAuthentication.SetAuthCookie(u.Username, true); u.IsActive = true; db.SaveChanges(); if (u.Role == "Admin") { return(RedirectToAction("Panel", "Home")); } else if (u.Role == "Company") { return(RedirectToAction("CompanyPanel", "Home")); } else if (string.IsNullOrEmpty(u.Role)) { return(RedirectToAction("Index", "Home")); } } else { ViewBag.LoginError = "Hatalı Kullanıcı Adı veya Şifre"; } return(View()); }
public ActionResult Register(User user, HttpPostedFileBase file) { ProjeContext db = new ProjeContext(); Setting setting = db.Settings.Where(x => x.Id == 1).FirstOrDefault(); var role = setting.NewUserDefaultRole; User rs = db.User.Where(x => x.Username.Contains(user.Username)).FirstOrDefault(); if (rs == null) { if (file != null && file.ContentLength > 0) { var newFileName = Guid.NewGuid() + System.IO.Path.GetExtension(file.FileName); var serverPath = Server.MapPath("/ProfilesPhotos"); var path = Path.Combine(serverPath, newFileName).Replace("\\", "/"); file.SaveAs(path); var userProfilePhotoPath = $@"/ProfilesPhotos/{newFileName}"; user.ProfilePhoto = userProfilePhotoPath; } user.Role = role; db.User.Add(user); db.SaveChanges(); FormsAuthentication.SetAuthCookie(user.Username, false); return(RedirectToAction("Index", "Home")); } else { ViewBag.Result = "Bu kullanıcı adı daha önceden alınmış!"; return(View()); } }
public ActionResult ListArticles(int?postId) { if (postId == null) { ProjeContext db = new ProjeContext(); List <Post> post = db.Post.ToList(); foreach (var item in post) { var categoryName = db.Category.Where(x => x.CategoryId == item.CategoryId).FirstOrDefault(); item.Category.CategoryName = categoryName.CategoryName; } return(View(post)); } else { ProjeContext db = new ProjeContext(); List <Post> post = db.Post.Where(x => x.PostId == postId).ToList(); foreach (var item in post) { var categoryName = db.Category.Where(x => x.CategoryId == item.CategoryId).FirstOrDefault(); item.Category.CategoryName = categoryName.CategoryName; return(View(post)); } } return(View()); }
public ActionResult ListMessages() { ProjeContext db = new ProjeContext(); List <Message> messages = db.Messages.ToList(); return(View(messages)); }
public ActionResult EditArticle(int?post_id, Post model, HttpPostedFileBase file) { if (post_id != 0) { ProjeContext db = new ProjeContext(); Post post = db.Post.Where(x => x.PostId == post_id).FirstOrDefault(); post.PostTitle = model.PostTitle; post.PostText = model.PostText; post.CategoryId = model.CategoryId; if (file != null && file.ContentLength > 0) { var postPicturePath = Server.MapPath(post.PostImage); if (System.IO.File.Exists(postPicturePath)) { System.IO.File.Delete(postPicturePath); } var newFileName = Guid.NewGuid() + System.IO.Path.GetExtension(file.FileName); var serverPath = Server.MapPath("/PostsPhotos"); var path = Path.Combine(serverPath, newFileName).Replace("\\", "/"); file.SaveAs(path); var postPhotoPath = $@"/PostsPhotos/{newFileName}"; post.PostImage = postPhotoPath; } db.SaveChanges(); return(RedirectToAction("ListArticles", "Home")); } return(View()); }
public ActionResult MyProfile(HttpPostedFileBase file, User model) { ProjeContext db = new ProjeContext(); User user = db.User.Where(x => x.Username == HttpContext.User.Identity.Name).FirstOrDefault(); user.Password = model.Password; if (file != null && file.ContentLength > 0) { var newFileName = Guid.NewGuid() + System.IO.Path.GetExtension(file.FileName); var serverPath = Server.MapPath("/ProfilesPhotos"); var path = Path.Combine(serverPath, newFileName).Replace("\\", "/"); file.SaveAs(path); var userProfilePhotoPath = $@"/ProfilesPhotos/{newFileName}"; user.ProfilePhoto = userProfilePhotoPath; } db.SaveChanges(); return(RedirectToAction("MyProfile")); }
public ActionResult AddMessage(UserMessage Model) { ProjeContext db = new ProjeContext(); db.UserMessages.Add(Model); db.SaveChanges(); return(RedirectToAction("ListMessages", "Home")); }
public ActionResult EditAnnouncement(int announcement_id, Announcement model) { ProjeContext db = new ProjeContext(); Announcement announcement = db.Announcement.Where(x => x.AnnouncementId == announcement_id).FirstOrDefault(); announcement.AnnouncementText = model.AnnouncementText; db.SaveChanges(); return(RedirectToAction("ListsAnnouncement", "Home")); }
public ActionResult DeleteAnnouncementOK(int announcement_id) { ProjeContext db = new ProjeContext(); Announcement announcement = db.Announcement.Where(x => x.AnnouncementId == announcement_id).FirstOrDefault(); db.Announcement.Remove(announcement); db.SaveChanges(); return(RedirectToAction("ListsAnnouncement", "Home")); }
public ActionResult DeleteMessage(int?messageId) { ProjeContext db = new ProjeContext(); Message message = db.Messages.Where(x => x.Id == messageId).FirstOrDefault(); db.Messages.Remove(message); db.SaveChanges(); return(RedirectToAction("ListMessages")); }
public ActionResult EditComment(int?commentId) { if (commentId != null) { ProjeContext db = new ProjeContext(); Comment comment = db.Comment.Where(x => x.CommentId == commentId).FirstOrDefault(); return(View(comment)); } return(RedirectToAction("NotFound")); }
public ActionResult DeleteCategory(int?category_id) { if (category_id != 0) { ProjeContext db = new ProjeContext(); Category category = db.Category.Where(x => x.CategoryId == category_id).FirstOrDefault(); return(View(category)); } return(View()); }
public ActionResult DeleteUser(int?user_id) { if (user_id != 0) { ProjeContext db = new ProjeContext(); User user = db.User.Where(x => x.UserId == user_id).FirstOrDefault(); return(View(user)); } return(RedirectToAction("NotFound", "Error")); }
public ActionResult Logout() { ProjeContext db = new ProjeContext(); var current_user = db.User.Where(x => x.Username.Contains(HttpContext.User.Identity.Name)).FirstOrDefault(); current_user.IsActive = false; db.SaveChanges(); FormsAuthentication.SignOut(); return(RedirectToAction("Login")); }
public ActionResult CommentAdd(Comment model, string User) { ProjeContext db = new ProjeContext(); model.PublishDate = DateTime.Now; model.Username = User; db.Comment.Add(model); db.SaveChanges(); return(RedirectToAction("ListComments", "Home")); }
public ActionResult ListCategories() { ProjeContext db = new ProjeContext(); List <Category> categories = db.Category.ToList(); if (categories != null) { return(View(categories)); } return(View()); }
public ActionResult CreateCategory(Category category) { if (category != null) { ProjeContext db = new ProjeContext(); db.Category.Add(category); db.SaveChanges(); return(RedirectToAction("ListCategories", "Home")); } return(RedirectToAction("NotFound", "Error")); }
public ActionResult AnnouncementAdd(Announcement model) { if (model != null) { ProjeContext db = new ProjeContext(); db.Announcement.Add(model); db.SaveChanges(); return(RedirectToAction("ListsAnnouncement", "Home")); } return(View()); }
public ActionResult MyProfileDeleteMessage(int?messageId) { ProjeContext db = new ProjeContext(); UserMessage userMessage = db.UserMessages.Where(x => x.Id == messageId).FirstOrDefault(); db.UserMessages.Remove(userMessage); db.SaveChanges(); var data = db.User.Where(x => x.UserId == userMessage.UserId).FirstOrDefault(); int?id = data.UserId; return(RedirectToAction("MyProfileListMessages", new { id })); }
public ActionResult SentMessages() { ProjeContext db = new ProjeContext(); List <UserMessage> userMessages = db.UserMessages.ToList(); foreach (var item in userMessages) { var incomingData = db.User.Where(x => x.UserId == item.UserId).FirstOrDefault(); item.User.Username = incomingData.Username; } return(View(userMessages)); }
public ActionResult ReadMore(int?post_id) { ProjeContext db = new ProjeContext(); Post post = db.Post.Where(x => x.PostId == post_id).FirstOrDefault(); post.TotalViews = post.TotalViews + 1; List <Comment> ct = db.Comment.Where(x => x.PostId == post_id).ToList(); post.Comments = ct; db.SaveChanges(); return(View(post)); }
public ActionResult DeleteArticle(int?post_id) { if (post_id != 0) { ProjeContext db = new ProjeContext(); Post post = db.Post.Where(x => x.PostId == post_id).FirstOrDefault(); var categoryName = db.Category.Where(x => x.CategoryId == post.CategoryId).FirstOrDefault(); post.Category.CategoryName = categoryName.CategoryName; return(View(post)); } return(View()); }