public bool CreatePost(PostCreate model) { var entity = new Post() { AuthorId = _userId, Title = model.Title, Text = model.Text, }; using (var ctx = new ApplicationDbContext()) { ctx.Posts.Add(entity); return(ctx.SaveChanges() == 1); } }
public IHttpActionResult Post(PostCreate post, int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreatePostService(id); if (!service.CreatePost(post)) { return(InternalServerError()); } return(Ok()); }
private string UploadedFile(PostCreate model) { string uniqueFileName = null; if (model.Img != null) { string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "images"); uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Img.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { model.Img.CopyTo(fileStream); } } return(uniqueFileName); }
public bool CreatePost(PostCreate model) { var entity = new Post() { Author = _userId, PostTitle = model.PostTitle, PostText = model.PostText, PostCreatedUtc = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Posts.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreatePost(PostCreate model) // make this Post, not User. Create a User Service for those methods { var entity = new Post() { UserId = _userId, // Id = model.Id, Title = model.Title, Text = model.Text, }; using (var ctx = new ApplicationDbContext()) { ctx.Posts.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreatePost(PostCreate model) { var entity = new Post() { Id = model.PostId, Title = model.Title, Text = model.Text, }; using (var ctx = new ApplicationDbContext()) { entity.Author = ctx.Users.Where(e => e.Id == _userId).First(); ctx.Posts.Add(entity); return(ctx.SaveChanges() == 2); } }
public bool CreatePost(PostCreate model) { var entity = new Post() { PostID = model.PostID, PostTitle = model.PostTitle, PostText = model.PostText, Author = model.Author }; using (var ctx = new ApplicationDbContext()) { ctx.Posts.Add(entity); return(ctx.SaveChanges() == 1); } }
public IHttpActionResult Post([FromBody] PostCreate post) { //Check if model state is valid if (!ModelState.IsValid) { return(BadRequest(ModelState)); } PostService Service = CreatePostService(); //Call my CreatePost From PostService and make sure the Post was created if (!Service.CreatePost(post)) { return(InternalServerError()); } return(Ok("Your Post Was Successfully Created.")); }
//POST public bool CreatePost(PostCreate model) { var newPost = new Post() { OwnerId = _userId, Title = model.Title, Content = model.Content, CreatedUtc = DateTimeOffset.Now }; using (var dataBase = new ApplicationDbContext()) { dataBase.Posts.Add(newPost); return(dataBase.SaveChanges() == 1); } }
public ActionResult CreatePost(PostCreate model, Guid id) { var service = CreatePostService(); var entity = service.PostModelCreate(model, id); //var service = CreatePostService(); if (service.CreatePost(entity)) { ViewBag.SaveResult = "You Posted!"; return RedirectToAction("Index"); } ModelState.AddModelError("", "Post could not be created."); return View(model); }
//private readonly int PostID; //public PostServices(int commentID) //{ // PostID = commentID; //} public bool CreatePost(PostCreate model) { var entity = new Post() { UserID = model.UserID, Title = model.Title, Text = model.Text //Author = model.Author }; using (var ctx = new ApplicationDbContext()) { ctx.Posts.Add(entity); var testing = ctx.SaveChanges(); return(true); } }
public bool CreatePost(PostCreate model) { var entity = new Post() { PostId = Guid.NewGuid(), DiscussionId = model.DiscussionId, CreatorId = _userId, Body = model.Body, CreatedUTC = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Posts.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(PostCreate model, int threadID) { if (!ModelState.IsValid) { return(View(model)); } var service = CreatePostService(); if (service.CreatePost(model, threadID)) { TempData["SaveResult"] = "Your post was created."; return(RedirectToAction("ThreadPostsIndex", "Post", new { threadID })); } ModelState.AddModelError("", "Post could not be created."); return(View(model)); }
public bool CreatePost(PostCreate model) { var entity = new Post() { //PostID = _postID -- Do not actually need PostTitle = model.PostTitle, PostText = model.PostText, UserID = model.UserID, CreatedUtc = DateTimeOffset.Now, }; using (var ctx = new ApplicationDbContext()) { ctx.Posts.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreatePost(PostCreate model) { var entity = new Post() { OwnerId = _userId, Title = model.Title, Content = model.Content, UserName = model.UserName, CreateUtc = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Posts.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreatePost(PostCreate model) { var entity = new Post() { PostUserID = _userID, AboutUserID = model.AboutUserID, Title = model.Title, Content = model.Content, Status = Status.Pending, CreateUTC = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Posts.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(PostCreate model) { if (!ModelState.IsValid) { ModelState.AddModelError("", "Post could not be created."); return(RedirectToAction("Detials", "MasterGroup", new { id = model.GroupID })); } var service = CreatePostService(); if (service.CreatePost(model)) { return(RedirectToAction("Detials", "MasterGroup", new { id = model.GroupID })); // I want to figure out how to have the comment then display on the page instead of a reroute to the index } ; return(View(model)); }
public ActionResult Create(PostCreate model) { var db = new ArtistService(); ViewBag.ArtistID = new SelectList(db.GetArtists().ToList(), "ArtistID", "ArtistName"); if (!ModelState.IsValid) { return(View(model)); } var service = CreatePostService(); if (service.CreatePost(model)) { TempData["SaveResult"] = "Your post was created."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Post could not be created."); return(View(model)); }
public async Task CreateAndDeletePostTest() { WordPressClient client = await GetAuthenticatedWordPressClient(); var IsValidToken = await client.IsValidJWToken(); Assert.IsTrue(IsValidToken); var newpost = new PostCreate() { Content = "Testcontent" }; var resultPost = await client.CreatePost(newpost); Assert.IsNotNull(resultPost.Id); var del = await client.DeletePost(resultPost.Id); Assert.IsTrue(del.IsSuccessStatusCode); }
public bool CreatePost(PostCreate model) { var service = CreateUserService(); var entity = new Post() { Author = service.GetUserByGUID(_userId), Title = model.Title, Text = model.Text, CreatedUtc = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Posts.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(PostCreate model) { model.DiscussionId = Guid.Parse(this.Session["currentDiscussion"].ToString()); if (!ModelState.IsValid) { return(View(model)); } var service = CreatePostService(); if (service.CreatePost(model)) { TempData["ResultSaved"] = "Post was created."; return(Redirect(Url.RouteUrl(new { controller = "Post", action = "Index", discussionId = Session["currentDiscussion"] }) + "#new_reply")); } ModelState.AddModelError("", "Post could not be created."); return(View(model)); }
public bool CreatePost(PostCreate model) { if (model.UserType == UserType.company) { var entity = new Post() { UserId = _userId, AnimalId = model.AnimalId }; using (var db = new ApplicationDbContext()) { db.Posts.Add(entity); return(db.SaveChanges() == 1); } } else { Console.WriteLine("Would you like to make a company account?"); } return(false); }
public async Task <ActionResult> CreatePost([FromBody] PostCreate model) { try { var entity = _mapper.Map <Post>(model); entity.AuthorId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; entity.CreatedAt = DateTime.Now; await _postService.Insert(entity); if (entity.Id != null) { if (model.CategoriesId.Any()) { List <Post_Category> post_Categories = model.CategoriesId.Select(x => new Post_Category { CategoryId = x, PostId = entity.Id }).ToList(); await _post_CategoryService.InsertRange(post_Categories); } return(Created($"/api/Posts/{entity.Id}", new { IdPost = entity.Id })); } else { ModelState.AddModelError(string.Empty, "Invalid attempt."); return(BadRequest(ModelState)); } } catch (Exception ex) { _logger.LogCritical(ex.Message); return(BadRequest()); } }
public bool CreatePost(PostCreate model) { if (model.Upload != null && model.Upload.ContentLength > 0) { var avatar = new Photo { PhotoName = System.IO.Path.GetFileName(model.Upload.FileName), FileType = FileType.Picture, ContentType = model.Upload.ContentType }; using (var reader = new System.IO.BinaryReader(model.Upload.InputStream)) { avatar.Content = reader.ReadBytes(model.Upload.ContentLength); } model.Files = new List <Photo> { avatar }; } var entity = new Post() { OwnerID = _userID, Title = model.Title, ArtistID = model.ArtistID, Artist = model.Artist, TattooDetails = model.TattooDetails, Files = model.Files, Upload = model.Upload, }; using (var ctx = new ApplicationDbContext()) { ctx.Posts.Add(entity); int actual = ctx.SaveChanges(); return(actual >= 1); } }
public async Task CreateAndDeletePostTest() { var client = new WordPressClient(ApiCredentials.WordPressUri); client.Username = ApiCredentials.Username; client.Password = ApiCredentials.Password; client.AuthMethod = AuthMethod.JWT; await client.RequestJWToken(); var IsValidToken = await client.IsValidJWToken(); Assert.IsTrue(IsValidToken); var newpost = new PostCreate() { Content = "Testcontent" }; var resultPost = await client.CreatePost(newpost); Assert.IsNotNull(resultPost.Id); var del = await client.DeletePost(resultPost.Id); Assert.IsTrue(del.IsSuccessStatusCode); }
//CREATE public bool CreatePost(PostCreate model) { using (var db = new ApplicationDbContext()) { var userProfile = db.Profiles.SingleOrDefault(p => p.UserID == _userId); if (userProfile == null) { var svc = new ProfileService(_userId); svc.CreateProfile(_userId); } var entity = new Post() { UserID = _userId, Title = model.Title, Body = model.Body, TimePosted = DateTimeOffset.Now, Profile = db.Profiles.Single(p => p.UserID == _userId) }; db.Posts.Add(entity); return(db.SaveChanges() == 1); } }
public PostCreateCommand(string space, PostCreate data, User user) : base(user) { Space = space; Data = data; }
public IActionResult Create([FromBody] PostCreate input) { var post = _postAppService.Create(input); return(Ok("Tạo thành công")); }
public virtual void OnPostCreate(Bundle savedInstanceState, Action <Bundle> baseOnPostCreate) { PostCreate?.Invoke(Target, new ValueEventArgs <Bundle>(savedInstanceState)); baseOnPostCreate(savedInstanceState); }
public int Create(PostCreate e) { return(Execute("insert into posts(id,title,preview,content,author,publish_date) values(:id,:title,:preview,:content,:author,:publish_date)", e)); }