Esempio n. 1
0
 public ActionResult CreatePost(Post post)
 {
     post.UserId    = WebSecurity.CurrentUserId;
     post.CreatedOn = DateTime.Now;
     _postRepository.AddPost(post);
     return(RedirectToAction("Details", new { id = post.GroupId }));
 }
Esempio n. 2
0
        public ViewResult PostForm(Post p, int id)
        {
            ViewBag.id = id;
            PostRepository pR = new PostRepository();

            if (ModelState.IsValid)
            {
                string check = pR.AddPost(p, id);
                if (check.Equals("post added"))
                {
                    List <Post> posts = pR.getAllPosts();
                    return(View("../User/HomeScreen", posts));
                }
                else if (check.Equals("post not added"))
                {
                    ModelState.AddModelError(String.Empty, "Your post could not be added.Try again!");
                    return(View());
                }
                return(View());
            }
            else
            {
                ModelState.AddModelError(String.Empty, "Please enter correct data");
                return(View());
            }
        }
Esempio n. 3
0
 public async Task <PostProto> CreatePost(Post post)
 {
     if (_postRepository.AddPost(post) > 0)
     {
         return(post);
     }
     return(null);
 }
Esempio n. 4
0
 public bool AddPost(Post post)
 {
     return(_postRepository.AddPost(new gRPC_si_EF_DATA.Entities.Post
     {
         PostId = Guid.Parse(post.PostId),
         Description = post.Description,
         Domain = post.Domain,
         Date = post.Date
     }));
 }
Esempio n. 5
0
 public ActionResult Create(Post post)
 {
     if (WebSecurity.CurrentUserId > 0)
     {
         post.UserId    = WebSecurity.CurrentUserId;
         post.CreatedOn = DateTime.Now;
         _postRepository.AddPost(post);
         return(RedirectToAction("MyPosts"));
     }
     return(RedirectToAction("Login", "Account"));
 }
Esempio n. 6
0
        public ActionResult Index()
        {
            var post = postRepasitory.AddPost(new Post()
            {
                Description = "aaa", ThreadId = 2, UserId = 1
            });

            // var post = postRepasitory.GetPost(48);
            //var post = postRepasitory.GetAllPosts(1);
            //postRepasitory.DeletePost(49);

            return(View());
        }
Esempio n. 7
0
        public ActionResult AddNewPost(PostViewModel post)
        {
            _postRepository.AddPost(new Post
            {
                Created      = DateTime.Now,
                Edited       = DateTime.Now,
                Introduction = post.Introduction,
                Content      = post.Content,
                Title        = post.Title
            });

            return(RedirectToAction("ViewPosts"));
        }
        public async Task ShouldGetPostFeedCorrect()
        {
            // Arrange
            var dbContext      = GetInMemoryDbContext();
            var postRepository = new PostRepository(dbContext);

            // This method creates two clubs and adds the first created user (see GetInMemoryDbContext method) to these clubs.
            // Just for reducing complexity ¯\_(ツ)_/¯
            var(userId, addedClub1, addedClub2) = await SetUpPostFeed(dbContext);

            postRepository.AddPost(new PostDto
            {
                ClubId = addedClub1.Id, Title = "Club1 Post1 Title1", Content = "Club1 Post1 Content1"
            });
            postRepository.AddPost(new PostDto
            {
                ClubId = addedClub2.Id, Title = "Club2 Post2 Title2", Content = "Club2 Post2 Content2"
            });

            var postResponse = await postRepository.GetMyPostFeedAsync(userId);

            // Assert
            Assert.Equal(2, postResponse.Count);
        }
Esempio n. 9
0
 public JObject AddPost(PostModel post, string UserId)
 {
     if (UserId == null || post.Content == null)
     {
         return(JObject.Parse("{ \"message\" : \"Put all data please!\", \"post\": " + JObject.FromObject(post) + ",  \"status\" : \"400\" }"));
     }
     else
     {
         object response = _postRepository.AddPost(post, UserId);
         if (response == null)
         {
             return(JObject.Parse("{ \"message\" : \"User id doesn't exist! use a valid user id\",  \"status\" : \"404\" }"));
         }
         return(JObject.Parse("{ \"message\" : \"Post added successfully!\", \"post\" : " + JObject.FromObject(post) + ", \"status\" : \"200\" }"));
     }
 }
Esempio n. 10
0
        public string AddPost(int postId, string title, string content)
        {
            string result = FAIL;

            try
            {
                if (postRepository.AddPost(postId, title, content))
                {
                    result = SUCCESS;
                }
            }
            catch (Exception ex)
            {
                ex.LogExceptionToFile();
                throw new Exception(ex.Message);
            }
            return(result);
        }
Esempio n. 11
0
        public ActionResult AddPost(PostModel Post)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    PostRepository PostRepo = new PostRepository();

                    if (PostRepo.AddPost(Post))
                    {
                        ViewBag.Message = "Added successfully";
                    }
                }

                return(View());
            }
            catch
            {
                return(View());
            }
        }
        public ViewResult CreatePost(Post p)    //saves post posted by the user in DB.
        {
            List <RegularUser> userData = UserRepository.ReturnUsers();
            RegularUser        ru       = userData.Find(ru => ru.Username == HttpContext.Session.GetString("CurrentUser"));

            if (ModelState.IsValid)
            {
                p.Date = System.DateTime.Now.ToString("dddd, dd MMMM yyyy h:mm:tt"); //save current time for the post
                p.Usr  = HttpContext.Session.GetString("CurrentUser");               //save current user for the post.
                PostRepository.AddPost(p);
                List <Post> postData = PostRepository.ReturnPosts();
                AdminController.manageProfilePic(ref postData);
                ViewBag.Id = ru.Id;
                postData.Reverse();
                return(View("~/Views/General/AtHome.cshtml", postData));
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Some data is missing !");
                return(View());
            }
        }
Esempio n. 13
0
        public IActionResult Add()
        {
            var form     = HttpContext.Request.Form;
            var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
            var text     = Markdown.ToHtml(form["text"], pipeline);
            //var content = form["main-text"];
            var title = form["title"];

            try
            {
                var us = _userRepository.GetUserByLogin(Request.Cookies["userLogin"]);
                _repository.AddPost(title, text, us.Id);
                //Helper.GetUserId(Request.Cookies["userLogin"]));
                return(ShowAllPosts());
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(View("~/Views/Shared/Error.cshtml", new ErrorPresenter()
                {
                    Exception = e
                }));
            }
        }
Esempio n. 14
0
 public void AddPost(PostModel newPost)
 {
     _postRepository.AddPost(newPost);
 }
 public IActionResult AddPost(string content)
 {
     postRepository.AddPost(content);
     return(RedirectToAction("Index"));
 }
 public ActionResult Create(Post post)
 {
     postRepository.AddPost(post);
     return(RedirectToAction("Display"));
 }
Esempio n. 17
0
 public void AddPosts(PostModel post)
 {
     _postRepo.AddPost(post);
 }
 public IActionResult AddNewPost(Post postToAdd)
 {
     _repo.AddPost(postToAdd);
     return(Created($"/ api / post /{ postToAdd.PostId}", postToAdd));
 }
Esempio n. 19
0
 public void Add(Post post)
 {
     postRepo.AddPost(post);
 }
Esempio n. 20
0
 public void AddPost(Post post)
 {
     postRepository.AddPost(post);
 }
Esempio n. 21
0
        public ActionResult AddPost(PostModel Post)
        {
            try
            {
                if (Post.Tags != null)
                {
                    if (ModelState.IsValid)
                    {
                        PostRepository PostRepo = new PostRepository();

                        if (PostRepo.AddPost(Post))
                        {
                            var submitteduser   = System.Web.HttpContext.Current.User.Identity.GetUserName();
                            var Infractiontitle = Post.Title;


                            ViewBag.Message = "Added successfully!!! (Submitted For Admin Review)";
                            PostRepository Profilerepo = new PostRepository();
                            //.Where(User => User.Title.StartsWith(search)
                            //.Select(Modelitems => Modelitems.getProcess.ToString()).FirstOrDefault()
                            //var Infractionusertag = Model.tagfilter.Where(Modelitems => Modelitems.user.Equals(item.user)).
                            //Select(Modelitems => Modelitems.getProcess.ToString()).FirstOrDefault();

                            var loginuser      = System.Web.HttpContext.Current.User.Identity.GetUserName();
                            var loginusertrack = Profilerepo.Users().Where(Users => Users.user == loginuser).Select(Users => Users.getProcess.ToString()).FirstOrDefault();
                            var loginAdmin     = Profilerepo.Users().Where(Users => Users.getProcess == loginusertrack).ToList();

                            var _ctx = new ApplicationDbContext();
                            // var roles = context.Roles.ToList();
                            var usersWithRoles = (from user in _ctx.Users
                                                  select new
                            {
                                Usernamee = user.UserName,
                                Email = user.Email,
                                RoleNames = (from userRole in user.Roles

                                             join role in _ctx.Roles on userRole.RoleId equals role.Id
                                             where role.Name == "Admin"
                                             select role.Name).ToList()
                            }).ToList().Select(p => new UserViewModel()

                            {
                                Usernamee = p.Usernamee,
                                Emaill    = p.Email,
                                Rolee     = string.Join(",", p.RoleNames)
                            });
                            var roleuser = usersWithRoles.Where(Users => Users.Rolee == "Admin").ToList();
                            //  var user = await UserManager.FindAsync(model.UserName, model.Password);
                            foreach (var item in loginAdmin)
                            {
                                var emailuser = roleuser.Where(Users => Users.Usernamee == item.user).Select(Users => Users.Emaill.ToString()).FirstOrDefault();

                                if (emailuser != null)
                                {
                                    string subject = submitteduser + " " + "from " + loginusertrack + " " + "posted infraction for review ";

                                    string body = PopulateBody(submitteduser, loginusertrack, Infractiontitle);

                                    SendHtmlFormattedEmail(emailuser, subject, body);
                                }
                            }
                        }
                        else
                        {
                            ViewBag.Message = "Duplicate Entry";
                        }
                        //  ModelState.Clear();
                    }
                }

                return(View());
            }
            catch
            {
                return(View());
            }
        }
Esempio n. 22
0
 public IActionResult Post(Post post)
 {
     post.CreateDateTime = DateTime.Now;
     _postRepository.AddPost(post);
     return(CreatedAtAction("Get", new { id = post.Id }, post));
 }
Esempio n. 23
0
 public void AddPost(PostModel post) => _postRepository.AddPost(post);
 public PostDTO AddPost(Post post)
 {
     return(_postRepository.AddPost(post));
 }
Esempio n. 25
0
 public void AddPost(string content, string title, string userName)
 {
     postRepository.AddPost(content, title, userName);
 }