public async Task <ActionResult <Post> > PostPost(Post post) { post.UserId = AuthService.GetUserId(User); await PostService.Add(post); return(CreatedAtAction("GetPost", new { id = post.Id }, post)); }
public ActionResult PostMessage(PostDTO post) { if (!ModelState.IsValid) { return(Json(null)); } PostDTO addedPost; try { addedPost = PostService.Add(post.CourseId, post.Message); if (addedPost != null && Request.Files.Count > 0) { FileService.Attach(addedPost.Id, addedPost.CourseId, Request.Files); addedPost = PostService.Get(addedPost.Id); } } catch (AccessViolationException) { return(RedirectToAction("Error", "Account", new { ErrorCase.UnauthorizedAccess })); } return(Json(addedPost)); }
public ActionResult Create(PostModels p, HttpPostedFileBase Image) { if (!ModelState.IsValid || Image == null || Image.ContentLength == 0) { RedirectToAction("Create"); } p.Image = Image.FileName; try { Post post = new Post { PostId = p.Id, Title = p.Title, Description = p.Description, Privacy = p.Privacy, Image = p.Image, PostDateTime = DateTime.Now }; ps.Add(post); ps.Commit(); //ps.Dispose(); var path = Path.Combine(Server.MapPath("~/Content/images/"), Image.FileName); Image.SaveAs(path); return(RedirectToAction("Index")); } catch { return(View()); } }
public async Task Create_Post_Creates_New_Post_Via_Context() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "Add_Post_Writes_Post_To_Database").Options; //Arrange using (var ctx = new ApplicationDbContext(options)) { var postService = new PostService(ctx); var post = new Post { Title = "New Test Post", Content = "some content in post" }; await postService.Add(post); } //Act using (var ctx = new ApplicationDbContext(options)) { //Assert Assert.AreEqual(1, ctx.Posts.CountAsync().Result); Assert.AreEqual("New Test Post", ctx.Posts.SingleAsync().Result.Title); } }
public async Task Create_Post_Creates_New_Post_Via_Context() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "Add_Post_Writes_Post_To_Database").Options; // run the test against one instance of the context using (var ctx = new ApplicationDbContext(options)) { var postService = new PostService(ctx); var post = new Post() { Title = "writing functional javascript", Content = "some post content" }; await postService.Add(post); } // use a separate instance of the context to verify correct data was saved to the db using (var ctx = new ApplicationDbContext(options)) { Assert.AreEqual(1, ctx.Posts.CountAsync().Result); Assert.AreEqual("writing functional javascript", ctx.Posts.SingleAsync().Result.Title); } }
public void AddPostTest() { postService.Add(new Post() { Id = 1, Text = "Content" }); Assert.Equal(1, DbContext.Posts.Count(p => p.Text == "Content")); }
public ActionResult Create(Post post) { try { post.TimeCreated = DateTime.Now; postService.Update(post, post.Id); postService.Add(post); var user = userService.Get(post.UserId); user.PostIds.Add(post.Id); userService.Update(user, user.Id); return(RedirectToAction(nameof(Index))); } catch { return(NotFound()); } }
public async Task <IActionResult> Create([Bind("Id,Title,Description,CreateTime,Body,Published")] Post post) { if (ModelState.IsValid) { await _postService.Add(post); return(RedirectToAction(nameof(Index))); } return(View(post)); }
public Post Post() { var i = User; Post post = new Post { Title = Request.Form["title"], Body = Request.Form["body"] }; IFormFile file = Request.Form.Files["file"]; return(postService.Add(post, file)); }
public void AddPostTests() { var builder = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()); applicationDbContext = new ApplicationDbContext(builder.Options, _configuration); repository = new Repository <Post>(applicationDbContext); postService = new PostService(repository); postService.Add(new Post() { Id = Guid.Parse("efd081d5-dcc5-4e70-9ac0-d26a5b9aa293"), Title = "Title", Content = "Content" }); Assert.Equal(1, applicationDbContext.Posts.Count(p => p.Title == "Title")); }
public ActionResult Create(PostViewModel pvm, CategoryPostViewModel id) { var c = Ps.GetAll(); foreach (var item in c) { CategoryPostViewModel Cvm = new CategoryPostViewModel(); Cvm.categorypostId = item.categorypostId; Cvm.nom = item.nom; /*Cvm.categoryId = item.categoryId; * Cvm.description = item.description; * Cvm.plan = item.plan; * Cvm.goals = item.goals; * Cvm.state = (WebApplication1.Models.stat)stat.To_Do;*/ } // ViewBag.cat = new SelectList(c, "projectId", "projectname"); Post p = new Post(); p.postId = pvm.postId; //p.categoriepostId=id.categorypostId; p.categorypostId = id.categorypostId; p.post_like = pvm.post_like; p.posttitre = pvm.posttitre; p.content = pvm.content; p.datepost = DateTime.Now; //// p.catgoriepostId = id.categorypostId; // p.content = pvm.content; // //p.userId = 1; //// p.user.Id = pvm.user.Id; Ts.Add(p); Ts.Commit(); try { // TODO: Add insert logic here return(RedirectToAction("listepost")); } catch { return(View()); } }
public void Add_EmptyTitle_ShouldFail() { Blog twitter; Post post; int beforeInsertCount; using (var dbContext = new BloggingDbContext(_contextOptions)) { bool hasTwitter = dbContext.Blogs .Where(b => b.Url.Contains("twitter")) .Count() > 0; if (!hasTwitter) { dbContext.Blogs.Add(new Blog { Url = "www.twitter.com" }); dbContext.SaveChanges(); } twitter = dbContext.Blogs .Where(b => b.Url.Contains("twitter")) .Single(); post = new Post { Title = "", Content = "lahfpwqohavskjlsbatuwqhaps;vddsah", Blog = twitter }; beforeInsertCount = dbContext.Posts.Count(); } int result; using (var dbContext = new BloggingDbContext(_contextOptions)) { PostService service = new PostService(dbContext); result = service.Add(post.Title, post.Content, twitter.Url); } using (var dbContext = new BloggingDbContext(_contextOptions)) { Assert.AreEqual(0, result); Assert.AreEqual(beforeInsertCount, dbContext.Posts.Count()); } }
public void Shoud_Not_Add_Post_Without_Author() { var post = new Post(); post.Title = "Post Title"; post.Body = "Post body."; post.IsPublished = true; var postValidation = new PostValidation(); var postRepository = new FakePostRepository(); var postService = new PostService(postRepository, postValidation); var result = postService.Add(post); Assert.IsFalse(result.IsValid); Assert.IsTrue(result.Errors.Count == 1); Assert.IsTrue(result.Errors[0].PropertyName == "Author.Id"); }
public void Add_ValidInputData_ShouldSucceed() { Blog blog = new Blog { Url = "www.instagram.com" }; Post post = new Post { Title = "How summer activities changed how we think about death", Content = "lksahfpwqohavskjlsbatuwqhaps;vddsah", Blog = blog }; int beforeInsertCount; using (var dbContext = new BloggingDbContext(_contextOptions)) { dbContext.Blogs.Add(blog); dbContext.SaveChangesAsync(); beforeInsertCount = dbContext.Posts.Count(); } int result; using (var dbContext = new BloggingDbContext(_contextOptions)) { PostService service = new PostService(dbContext); result = service.Add(post.Title, post.Content, blog.Url); } using (var dbContext = new BloggingDbContext(_contextOptions)) { Assert.AreEqual(1, result); Assert.AreEqual(beforeInsertCount + 1, dbContext.Posts.Count()); var newlyAddedPost = dbContext.Posts .Include(p => p.Blog) .Where(p => p.Title.Contains("How summer activities changed how we think about death")) .Single(); Assert.AreEqual(post.Title, newlyAddedPost.Title); Assert.AreEqual(post.Content, newlyAddedPost.Content); Assert.IsNotNull(newlyAddedPost.Blog); Assert.AreEqual(post.Blog.Url, newlyAddedPost.Blog.Url); } }
public async Task Add_WritesToDatabase() { //Arrange var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "Add_Dtabase") .Options; //Act // Run the test against one instance of the context using (var context = new ApplicationDbContext(options)) { var postService = new PostService(context); await postService.Add(new Post()); } // Assert // Use a separate instance of the context to verify correct data was saved to database using (var context = new ApplicationDbContext(options)) { Assert.Equal(expected: 1, actual: context.Posts.Count()); } }
public ActionResult RePost(long rePostId, string content, string ip, string city) { if (Session["userId"] == null) { return(Json(new AjaxResult { Status = "NoLogin", ErrorMsg = "Not logged in user" })); } var post = PostService.GetPostInfo(rePostId); if (post == null) { return(Json(new AjaxResult { Status = "Failed", ErrorMsg = "Please refresh and try again" })); } PostService.Add(Convert.ToInt64(Session["userId"]), content, post.DisplayUrl, city); LogService.Add(Convert.ToInt64(Session["userId"]), 2, string.Format("{0}在{1}转发帖子成功", Session["userName"], city), ip); return(Json(new AjaxResult { Status = "OK" })); }
public ActionResult Create(Post data, HttpPostedFileBase Image) { List <string> UploadImagePaths = new List <string>(); UploadImagePaths = ImageUploader.UploadSingleImage(ImageUploader.OriginalProfileImagePath, Image, 1); data.ImagePath = UploadImagePaths[0]; if (data.ImagePath == "0" || data.ImagePath == "1" || data.ImagePath == "2") { data.ImagePath = ImageUploader.DefaultProfileImagePath; data.ImagePath = ImageUploader.DefaultXSmallProfileImagePath; data.ImagePath = ImageUploader.DefaultCruptedProfileImagePath; } else { data.ImagePath = UploadImagePaths[1]; data.ImagePath = UploadImagePaths[2]; } _postService.Add(data); return(Redirect("/Admin/Post/List")); }
public ActionResult Posting(string content, string base64Data, string ip, string city) { if (Session["userId"] == null) { Session.Clear(); //return Json(new AjaxResult { Status = "Error", ErrorMsg = "未登录用户" }); return(Redirect("/User/Login")); } //上传到文件服务器(七牛云) string url = Common.ImageHelper.UploadStream(Common.ImageHelper.ImgBase64ToStream(base64Data)); if (string.IsNullOrEmpty(url)) { return(Json(new AjaxResult { Status = "Failed", ErrorMsg = "Failed to upload picture" })); } PostService.Add(Convert.ToInt64(Session["userId"]), content, url, city); LogService.Add(Convert.ToInt64(Session["userId"]), 2, string.Format("{0}在{1}发帖成功", Session["userName"], city), ip); return(Json(new AjaxResult { Status = "OK" })); }
public async Task <ResponceModel> Add([FromBody] Post model) { var identifier = User.Claims.FirstOrDefault(p => p.Type == "id"); if (identifier == null) { return(new ResponceModel(401, "FAILED", null, new string[] { "Yetkilendirme Hatası." })); } try { var user = (await _userService.GetById(int.Parse(identifier.Value))); var post = await postService.Add(model); if (user.Id != post.UserId) { return(new ResponceModel(401, "FAILED", null, new string[] { "Yetkilendirme Hatası." })); } if (await postService.SaveChangesAsync()) { return(new ResponceModel(200, "OK", post, null)); } else { return(new ResponceModel(400, "FAILD", null, new string[] { "Gönderi eklenirken bir sorun oluştu." })); } } catch (Exception ex) { await _logService.Add(new SystemLog() { Content = ex.Message, CreateDate = DateTime.Now, UserId = 0, EntityName = postService.GetType().Name }); return(new ResponceModel(500, "ERROR", null, new string[] { "Gönderi eklenirken bir hata oluştu." })); } }
public async Task Create_Post_Creates_New_Post_Via_Context() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; using (var ctx = new ApplicationDbContext(options)) { var postService = new PostService(ctx); var post = new Post { Title = "writing functional javascript", Content = "some post content" }; await postService.Add(post); } using (var ctx = new ApplicationDbContext(options)) { Assert.AreEqual(1, ctx.Posts.CountAsync().Result); Assert.AreEqual("writing functional javascript", ctx.Posts.SingleAsync().Result.Title); } }
static void CreateData() { string biography = "Why not live a life of your dreams?"; string profilePic = "https://scontent-hkg3-2.cdninstagram.com/vp/761993dc007e86f9968a9f938e80e70a/5B697B1A/t51.2885-19/s150x150/25005602_1904421042944210_7172550441782214656_n.jpg"; IUserService userService = new UserService(); var admin = userService.GetUserById(userService.Add("admin", "管理员", "123456")); userService.EditProfilePic(admin.Id, profilePic); userService.Edit(admin.Id, admin.UserName, admin.FullName, biography, false, true, "*****@*****.**", "000000000"); List <UserEntity> userList = new List <UserEntity>() { admin }; IFollowService followService = new FollowService(); IPostService postService = new PostService(); #region PostDic Dictionary <string, string> dic = new Dictionary <string, string> { { "#IGCD |#sichuan |#shanghai |#guangzhou |#china |#beijing |#chinese |#hongkong |#hotpot |#上海 |#重庆 |#广州 |#成都 | #北京 | #四川 | #英国 |#中国 |#chongqing", "https://scontent-hkg3-2.cdninstagram.com/vp/81fbc5469b0214b401df906188a9d203/5B5E989F/t51.2885-15/e35/30076807_185022462128987_2634373999806644224_n.jpg" }, { @"Photo illustration by karencantuq After a few weeks of sickness, Lily the golden retriever is finally back to her usual antics. “When we left the vet, you could see her excitement,” says her human, visual artist Karen Cantu Quintanilla(karencantuq). “She ran toward these plants and started playing around, getting all muddy.My heart smiled, watching her being herself.” 💗🐞 Follow along to see more of our favorites from last weekend’s hashtag project, #WHPwildthing.", "https://scontent-hkg3-2.cdninstagram.com/vp/e38c381e89e706ef9635e33db6e16dbc/5B68BF71/t51.2885-15/e35/30591615_881741418699920_600203219846561792_n.jpg" }, { @"Photo by masoudoroudian Hanging out with a few cool cats in Tehran 🐾 #WHPwildthing", "https://scontent-hkg3-2.cdninstagram.com/vp/5a6c4d5c4160f1f8b59a58a4c7b98433/5B592BDC/t51.2885-15/e35/30590576_118389625684611_4178553869594263552_n.jpg" }, { @"Photo by reverieroaming “Some days you just gotta swap the office for the mountains and the Wi-Fi for the woods and go on a hike with your best friend,” writes Amy Lynn (reverieroaming) in her caption. #WHPwildthing", "https://scontent-hkg3-2.cdninstagram.com/vp/e49d5ac5eaa8758fa234c741c36f73af/5B71CBC5/t51.2885-15/e35/30087512_587995028236388_4322332280694505472_n.jpg" }, { @"Photo by michellevalbergphotography Jumping for joy at the arrival of spring snow. 😍 Follow along to see more of our favorites from last weekend’s hashtag project, #WHPwildthing.", "https://scontent-hkg3-2.cdninstagram.com/vp/33b9c5548e1f16fed5da48fc58ed828e/5B609D4A/t51.2885-15/e35/30084252_181096276041718_5268656572644458496_n.jpg" }, { "I am drawn to combining the sad with the beautiful", "https://scontent-hkg3-2.cdninstagram.com/vp/850789af95b9ca6167583d28fbddfb9a/5B73E8EE/t51.2885-15/e35/30087720_114361546087186_3830904802745778176_n.jpg" }, { @"_mijini 标记我分享你的自拍,让更多人看到你 #katy #perry #katyperry #pretty #beautiful #music #lovethissong #kp #katykats #katykat #katycats #katycat #caligirls #californiagirls #partofme #smile #instagood #instaperry #love #photooftheday #extraterrestrial #teenagedream #wideawake", "https://scontent-hkg3-2.cdninstagram.com/vp/a3323727d7d2cb514106c15c72080617/5B652D05/t51.2885-15/e35/21980719_147546825852833_1269593333424979968_n.jpg" }, { @"jhlii 标记我分享你的自拍,让更多人看到你 #katy #perry #katyperry #pretty #beautiful #music #lovethissong #kp #katykats #katykat #katycats #katycat #caligirls #californiagirls #partofme #smile #instagood #instaperry #love #photooftheday #extraterrestrial #teenagedream #wideawake", "https://scontent-hkg3-2.cdninstagram.com/vp/770dae4e2f8ad2dddce8aa831ec2d82b/5B5526CB/t51.2885-15/e35/21980601_133534460719251_2834026624008060928_n.jpg" }, { @"dj_siena 标记我分享你的自拍,让更多人看到你 #katy #perry #katyperry #pretty #beautiful #music #lovethissong #kp #katykats #katykat #katycats #katycat #caligirls #californiagirls #partofme #smile #instagood #instaperry #love #photooftheday #extraterrestrial #teenagedream #wideawake", "https://scontent-hkg3-2.cdninstagram.com/vp/62489e09ff9e0236c2166265c4322c6f/5B5DD01B/t51.2885-15/e35/21879373_1435036036615296_7736067429670846464_n.jpg" }, { @"@_bebe0519_ 标记我分享你的自拍,让更多人看到你 #happy #smile #fun #instahappy #goodmood #sohappy #happier #excited #feelgood #smiling #funtimes #funny #feliz #feelgood #feelgoodphoto #joy #happyhappy #enjoy #love #lovelife #instagood #laugh #laughing", "https://scontent-hkg3-2.cdninstagram.com/vp/0e03427b57ab6e76d63c2552b2572226/5B5F0E47/t51.2885-15/e35/21827267_133356903961013_3484997796107386880_n.jpg" }, { @"irisirisss90 标记我分享你的自拍,让更多人看到你 #fashion #style #stylish #love #me #cute #photooftheday #nails #hair #beauty #beautiful #instagood #instafashion #pretty #girly #pink #girl #girls #eyes #model #dress #skirt #shoes #heels #styles #outfit #purse #jewlery#shopping", "https://scontent-hkg3-2.cdninstagram.com/vp/c69904bcd3e5ec829598e5576643e029/5B6D6E97/t51.2885-15/e35/21827011_533848550292213_537823935178211328_n.jpg" }, { @"adelekok 标记我分享你的自拍,让更多人看到你 #fashion #style #stylish #love #me #cute #photooftheday #nails #hair #beauty #beautiful #instagood #instafashion #pretty #girly #pink #girl #girls #eyes #model #dress #skirt #shoes #heels #styles #outfit #purse #jewlery#shopping", "https://scontent-hkg3-2.cdninstagram.com/vp/ad6ace62d9bc8d8299d629309a8d5e40/5B66DB35/t51.2885-15/e35/21878934_381924075559203_5692128743028424704_n.jpg" }, { @"@babebani 标记我分享你的自拍,让更多人看到你 #fashion #style #stylish #love #me #cute #photooftheday #nails #hair #beauty #beautiful #instagood #instafashion #pretty #girly #pink #girl #girls #eyes #model #dress #skirt #shoes #heels #styles #outfit #purse #jewlery#shopping", "https://scontent-hkg3-2.cdninstagram.com/vp/ff246d161ff3cac22b0d2776a22842aa/5B5FC0D6/t51.2885-15/e35/21569404_1931782723706365_6424639826292637696_n.jpg" }, { @"_reiikoyuii 标记我分享你的自拍,让更多人看到你 #pretty #picstitch #tweegram #my #hair #jj #bored #life #swag #cool #funny #igdaily #family #repost #photo #pink #amazing #blue #girls #hot #中国", "https://scontent-hkg3-2.cdninstagram.com/vp/9a7abc5abda261c3dd922aec1e10a2a0/5B62C7EB/t51.2885-15/e35/21434220_1427843753978754_1111383342583906304_n.jpg" }, { @"tame__c 标记我分享你的自拍,让更多人看到你 #pretty #picstitch #tweegram #my #hair #jj #bored #life #swag #cool #funny #igdaily #family #repost #photo #pink #amazing #blue #girls #hot", "https://scontent-hkg3-2.cdninstagram.com/vp/edbfcf9ba4ea4306d25f18e2ef42f79a/5B50D478/t51.2885-15/e35/21371745_316477285484968_5420867168482885632_n.jpg" } }; #endregion CommentService commentService = new CommentService(); LikeService likeService = new LikeService(); for (int i = 1; i < 51; i++) { var user = userService.GetUserById(userService.Add("test" + i, "Test" + i, "123456")); userService.Edit(user.Id, user.UserName, user.FullName, biography, false, true, "*****@*****.**", "123456789"); userService.EditProfilePic(user.Id, profilePic); foreach (var item in dic) { var post = postService.GetPostInfo(postService.Add(user.Id, item.Key.Length > 100 ? item.Key.Substring(0, 99) : item.Key, item.Value, "重庆")); Console.WriteLine(string.Format("{0}发贴成功", user.UserName)); foreach (var userItem in userList) { commentService.Add(userItem.Id, post.Id, "Why not live a life of your dreams?"); likeService.Like(userItem.Id, post.Id); Console.WriteLine(string.Format("{0}评论点赞成功", userItem.UserName)); } //Thread.Sleep((int)RandomHelper.CreateId(5)); } foreach (var item in userList) { followService.Follow(user.Id, item.Id); } followService.Follow(user.Id, admin.Id); userList.Add(user); Console.WriteLine(string.Format("{0}用户已创建", user.UserName)); } //IPostService postService = new PostService(); //long postId = postService.Add(6502458435, "#123 #test askdjfla;sdf", "1.png"); //Console.WriteLine(postId); }
static async System.Threading.Tasks.Task Main(string[] args) { using (var db = new BloggingContext()) { try { db.Database.Migrate(); } catch (Exception ex) { Console.WriteLine("An error occurred migrating the DB."); Console.WriteLine(ex); } } using (var db = new BloggingContext()) { var blogs = await db.Blogs.ToListAsync(); var posts = await db.Posts.ToListAsync(); db.Blogs.RemoveRange(blogs); db.Posts.RemoveRange(posts); await db.SaveChangesAsync(); } var blogId = 0; using (var db = new BloggingContext()) { var blogService = new BlogService(db); blogService.Add("http://blogs.msdn.com/adonet"); blogId = blogService .Find(string.Empty) .Single() .BlogId; Console.WriteLine("{0} records saved to database", 1); } using (var db = new BloggingContext()) { var postService = new PostService(db); postService.Add(blogId, "Hello world!"); Console.WriteLine("{0} records saved to database", 1); } Console.WriteLine(); using (var db = new BloggingContext()) { var blogService = new BlogService(db); var blogs = blogService.Find(string.Empty); Console.WriteLine("All blogs in database:"); foreach (var blog in blogs) { Console.WriteLine(" - {0}", blog.Url); Console.WriteLine(" - {0}", blog.Posts.First().Title); } } }
//post请求 private void Post(SSORequest ssoRequest) { PostService ps = new PostService(); ps.Url = ConfigurationManager.AppSettings["SSOUrl"]; ps.Add("IsLogin", "1"); ps.Add("UserAccount", ssoRequest.UserAccount); ps.Add("AppCode", ssoRequest.AppCode); ps.Add("TimeStamp", ssoRequest.TimeStamp); ps.Add("AppUrl", ssoRequest.AppUrl); ps.Add("Authenticator", ssoRequest.Authenticator); ps.Post(); }
public IActionResult Add(Post post) { post.PostedDate = DateTime.Now; postService.Add(post); return(RedirectToAction("Index")); }
public void AddPost(int id, string text) { postService.Add(id, text); }