public ActionResult Create(Post post) { if (ModelState.IsValid) { post.Producer = User.Identity.Name; // post.ID = post._Content.GetHashCode().ToString(); if (post.GoogleMap == null) { post.GoogleMap = "https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d15196.733401840413!2d34.76801167151065!3d31.969372704850464!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x1502b3f5eb44e1c1%3A0xfbe9b8c6bce59319!2z15TXnteh15zXldecINeU15DXp9eT157XmSDXlNee15vXnNec15Qg15zXnteZ16DXlNec!5e0!3m2!1siw!2sil!4v1501339255742"; } if (post.Photo == null) { post.Photo = "https://cdn.dribbble.com/users/22251/screenshots/803201/no-photo-grey.png"; } pdb.Posts.Add(post); pdb.SaveChanges(); return(RedirectToAction("Index", "Home")); } else { ViewBag.Title = "New Event"; return(View(post)); } }
public ActionResult Create(Comment comment) { if (ModelState.IsValid) { comment.Author = User.Identity.Name; cdb.Comments.Add(comment); cdb.SaveChanges(); Post post = pdb.Posts.Find(comment.RefferedPost); IntegerData idata = new IntegerData(); idata.Data = comment.ID; post.Comments.Add(idata); pdb.Entry(post).State = EntityState.Modified; pdb.SaveChanges(); //if is hitchhiker if (comment.Hitchhiker == true) { Hitchhiker hitch = new Hitchhiker() { Name = comment.Author, Phone = comment.PhoneNumber, PostID = comment.RefferedPost }; hdb.Hitchhikers.Add(hitch); hdb.SaveChanges(); } return(RedirectToAction("Details", "Post", new { id = post.ID })); } else { return(View(comment)); } }
public IActionResult Create([Bind("Id,Title,Perex,Content,AuthorId,CreatedAt")] Post post) { if (ModelState.IsValid) { _context.Add(post); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(View(post)); }
public IActionResult AddPost([FromBody] Post item) { _context.posts.Add(item); _context.SaveChanges(); return(Ok(new { success = true, returncode = "200" })); }
public void AddComment(Comment comment, Guid postId) { var post = dbContext.Posts.Where(x => x.Id == postId).FirstOrDefault(); if (post != null) { post.Comments.Add(comment); dbContext.SaveChanges(); } }
public PostsController(PostsContext context) { _context = context; if (_context.posts.Count() == 0) { _context.posts.Add(new Post() { Title = "Cras interdum. Nunc sollicitudin commodo", Body = "lorem ipsum sodales purus, in molestie tortor nibh sit amet orci.", Date = "06/01/18, 1:08:54 PM", Author = "Slade" }); _context.posts.Add(new Post() { Title = "sollicitudin commodo ipsum. Suspendisse non", Body = "Proin sed turpis nec mauris blandit mattis. Cras eget nisi dictum augue", Date = "28/01/18, 10:05:34 AM", Author = "Griffith" }); _context.posts.Add(new Post() { Title = "risus odio, auctor vitae, aliquet", Body = "Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec tincidunt. Donec", Date = "21/10/18, 3:00:50 PM", Author = "Tobias" }); _context.posts.Add(new Post() { Title = "risus a ultricies adipiscing, enim", Body = "nec, eleifend non, dapibus rutrum, justo. Praesent luctus. Curabitur egestas nunc", Date = "23/03/19", Author = "Allistair" }); _context.posts.Add(new Post() { Title = "vestibulum, neque sed dictum eleifend,", Body = "velit eget laoreet posuere, enim nisl elementum purus, accumsan interdum libero dui nec", Date = "26/04/19, 11:08:54 PM", Author = "Brett" }); _context.posts.Add(new Post() { Title = "blandit at, nisi. Cum sociis", Body = "nisl. Quisque fringilla euismod enim. Etiam gravida molestie arcu. Sed eu nibh vulputate", Date = "25/07/19, 3:15:24 PM", Author = "Blake" }); _context.SaveChanges(); } }
internal PostsResp AddPosts(PostsTable post) { using (var db = new PostsContext()) { db.Posts.Add(post); db.SaveChanges(); return(new PostsResp() { Status = true, StatusMsg = "" }); } }
public ActionResult Follow(int Id) { using (var db = new PostsContext()) { db.Follows.Add(new Follow { Following = Id, Followers = ((LocalIdentity)ControllerContext.HttpContext.User.Identity).Id }); db.SaveChanges(); } return(View()); }
public ActionResult AddPost(string imgPath, string title, string text) { using (var db = new PostsContext()) { db.Posts.Add(new Post { ImgPath = imgPath, Title = title, Text = text }); db.SaveChanges(); } return(RedirectToAction("index")); }
public ActionResult Post(Post_ViewModel microblogs) { using (var db = new PostsContext()) { db.Posts.Add(new Microblog { Author = ControllerContext.HttpContext.User.Identity.Name, Content = microblogs.Content, Published = DateTime.Now }); db.SaveChanges(); return(View("Index")); } }
public ActionResult Register(RegistrationForm form) { if (string.IsNullOrWhiteSpace(form.Username) || string.IsNullOrWhiteSpace(form.Password) || string.IsNullOrWhiteSpace(form.PasswordConfirm) || string.IsNullOrWhiteSpace(form.EmailAddress)) { form.ErrorMessage = "All fields are required!"; return(View(form)); } if (form.Password != form.PasswordConfirm) { form.ErrorMessage = "Password and confirmation do not match!"; return(View(form)); } if (form.Password.Length < 8) { form.ErrorMessage = "Passwords must be at least 8 characters long"; return(View(form)); } using (var db = new PostsContext()) { // For a real setup, uncomment the email check, to require unique email addresses and usernames var account = db.Accounts.FirstOrDefault(a => a.Username == form.Username.ToLower() /* || a.EmailAddress == form.EmailAddress.ToLower() */); if (account != null) { form.ErrorMessage = "There is already an account with these details"; return(View(form)); } // Create the new account db.Accounts.Add(new Account { Username = form.Username.ToLower(), HashedPassword = Crypto.HashPassword(form.Password), EmailAddress = form.EmailAddress }); db.SaveChanges(); } return(RedirectToAction("Index", "Home")); }
public void AddUser(User user) { db.Users.Add(user); db.SaveChanges(); }
public ActionResult <Post> Post([FromBody] PostInsertRequest request) { var obj = _mapper.Map <Models.Post>(request); var check = _context.Posts.Where(w => w.title == request.title).FirstOrDefault(); if (check != null) { return(BadRequest()); } obj.createdAt = DateTime.Now; obj.updatedAt = DateTime.Now; obj.slug = Helpers.Helper.GenerateSlug(request.title); _context.Posts.Add(obj); _context.SaveChanges(); int PostID = obj.PostID; List <string> tags = _context.Tags.Select(s => s.title).ToList(); List <int> tagsID = _context.Tags.Select(s => s.TagID).ToList(); for (int i = 0; i < request.tagsList.Count; i++) { string reqTag = request.tagsList[i]; bool tagStored = false; for (int j = 0; j < tags.Count; j++) { string storedTag = tags[j]; if (reqTag == storedTag) { _context.PostsTags.Add( new Models.PostTag { PostID = PostID, TagID = tagsID[j] }); _context.SaveChanges(); tagStored = true; break; } } if (!tagStored) { Models.Tag newTag = new Models.Tag { title = reqTag }; _context.Tags.Add(newTag); _context.SaveChanges(); _context.PostsTags.Add( new Models.PostTag { PostID = PostID, TagID = newTag.TagID }); _context.SaveChanges(); } } var res = _context.Posts.Include("tagList.Tag").Where(w => w.PostID == PostID).FirstOrDefault(); return(_mapper.Map <Post>(res)); }