Example #1
0
        public ActionResult ListsAnnouncement()
        {
            ProjeContext        db           = new ProjeContext();
            List <Announcement> announcement = db.Announcement.ToList();

            return(View(announcement));
        }
Example #2
0
        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));
        }
Example #3
0
        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"));
        }
Example #4
0
        public ActionResult ListUsers()
        {
            ProjeContext db   = new ProjeContext();
            List <User>  user = db.User.ToList();

            return(View(user));
        }
Example #5
0
        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());
        }
Example #6
0
        public ActionResult ListComments()
        {
            ProjeContext   db       = new ProjeContext();
            List <Comment> comments = db.Comment.ToList();

            return(View(comments));
        }
Example #7
0
 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());
     }
 }
Example #8
0
        public ActionResult DeleteAnnouncement(int announcement_id)
        {
            ProjeContext db           = new ProjeContext();
            Announcement announcement = db.Announcement.Where(x => x.AnnouncementId == announcement_id).FirstOrDefault();

            return(View(announcement));
        }
Example #9
0
        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());
        }
Example #10
0
        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());
            }
        }
Example #11
0
        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());
        }
Example #12
0
        public ActionResult ListMessages()
        {
            ProjeContext   db       = new ProjeContext();
            List <Message> messages = db.Messages.ToList();

            return(View(messages));
        }
Example #13
0
        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());
        }
Example #14
0
        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"));
        }
Example #15
0
        public ActionResult AddMessage(UserMessage Model)
        {
            ProjeContext db = new ProjeContext();

            db.UserMessages.Add(Model);
            db.SaveChanges();
            return(RedirectToAction("ListMessages", "Home"));
        }
Example #16
0
        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"));
        }
Example #17
0
        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"));
        }
Example #18
0
        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"));
        }
Example #19
0
 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"));
 }
Example #20
0
 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());
 }
Example #21
0
 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"));
 }
Example #22
0
        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"));
        }
Example #23
0
        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"));
        }
Example #24
0
        public ActionResult ListCategories()
        {
            ProjeContext    db         = new ProjeContext();
            List <Category> categories = db.Category.ToList();

            if (categories != null)
            {
                return(View(categories));
            }
            return(View());
        }
Example #25
0
 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"));
 }
Example #26
0
 public ActionResult AnnouncementAdd(Announcement model)
 {
     if (model != null)
     {
         ProjeContext db = new ProjeContext();
         db.Announcement.Add(model);
         db.SaveChanges();
         return(RedirectToAction("ListsAnnouncement", "Home"));
     }
     return(View());
 }
Example #27
0
        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 }));
        }
Example #28
0
        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));
        }
Example #29
0
        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));
        }
Example #30
0
 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());
 }