public void AddPost(Post post) { try { if (ModelState.IsValid) { var reciever = userRepository.Get(post.RecieverId); var _post = new Post() { Text = post.Text, Sender = userRepository.Get(User.Identity.GetUserId()), Reciever = reciever, Date = DateTime.Now }; postRepository.Add(_post); postRepository.Save(); } else { throw new Exception(); } } catch (Exception ex) { } }
public ActionResult Create(Post model, HttpPostedFileBase Image) { List <string> UploadImagePaths = new List <string>(); UploadImagePaths = ImageUploader.UploadSingleImage(ImageUploader.OriginalProfileImagePath, Image, 1); model.ImagePath = UploadImagePaths[0]; if (model.ImagePath == "0" || model.ImagePath == "1" || model.ImagePath == "2") { model.ImagePath = ImageUploader.DefaultProfileImagePath; model.ImagePath = ImageUploader.DefaultXSmallProfileImage; model.ImagePath = ImageUploader.DefaulCruptedProfileImage; } else { model.ImagePath = UploadImagePaths[1]; model.ImagePath = UploadImagePaths[2]; } model.PublishDate = DateTime.Now; _postRepository.Add(model); return(Redirect("/Admin/Post/List")); }
public ActionResult Create(PostCreateViewModel model) { if (!ModelState.IsValid) { return(View()); } string fileName = Path.GetFileNameWithoutExtension(model.ImageFile.FileName); string extension = Path.GetExtension(model.ImageFile.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; model.postImageURL = "~/img/" + fileName; fileName = Path.Combine(Server.MapPath("~/img/"), fileName); model.ImageFile.SaveAs(fileName); Post newPost = new Post() { postContent = model.postContent, postDate = model.postDate, postDescription = model.postDescription, postImageURL = model.postImageURL }; user = UserManager.FindById(User.Identity.GetUserId()); newPost.CurrentUserId = user.Id; repository.Add(newPost); repository.SaveChanges(); ModelState.Clear(); return(RedirectToAction("List")); }
public async Task <int> AddPost() { RestService <Post> restService = new RestService <Post>(); Random random = new Random(); List <Post> posts = await restService.GetAsync("posts", random.Next(0, 100)); int adicionados = 0; PostRepository postRespository = new PostRepository(); foreach (Post post in posts) { Post validaPost = postRespository.Find(post.Id); if (validaPost == null) { UserRepository userRepository = new UserRepository(); User user = userRepository.Find(post.UserId); if (user == null) { UserViewModels.UsersViewModel userViewModel = new UserViewModels.UsersViewModel(); await userViewModel.ImportUser(post.UserId); } postRespository.Add(post); adicionados++; } } return(adicionados); }
public ActionResult Create(CreatePostRequest command) { if (!ModelState.IsValid) { return(View()); } if (IsExpire) { return(RedirectToAction("SignIn", "Auth")); } //add post using (var postRepo = new PostRepository()) { postRepo.Add(new Post { Title = command.Title, Content = command.Content, AuthorId = Me.Id, StatusId = Status.Author }); } return(RedirectToAction("Index")); }
public IActionResult Post(Post post) { User currentUser = GetCurrentUserProfile(); if (currentUser == null) { return(Unauthorized()); } post.UserId = currentUser.Id; post.CreateDate = DateTime.Now; //sanitize the html var sanitizer = new HtmlSanitizer(); post.Content = sanitizer.Sanitize(post.Content); //check for flagged words if (_flaggedWordService.HasFlaggedWord(post.Content)) { post.Flagged = true; } _postRepository.Add(post); return(CreatedAtAction(nameof(Get), new { id = post.Id }, post)); }
public void Post([FromBody] Post prod) { if (ModelState.IsValid) { _postRepository.Add(prod); } }
public ActionResult Create(PostAddViewModel addmodel, HttpPostedFileBase[] ImageFile) { if (addmodel.City != null && addmodel.Country != null && addmodel.Description != null && addmodel.Title != null && ImageFile != null) { Post post = PostAddViewModel.ToDB(addmodel); post.CreatedOn = DateTime.Now; post.UserId = User.Identity.GetUserId(); _postRepository.Add(post); string fulPathName = ConfigurationManager.AppSettings["UpladPath"]; string uploadFullPath = Server.MapPath(fulPathName); string endString = post.Id.ToString(); Directory.CreateDirectory(uploadFullPath + endString); int i = 0; foreach (var pp in ImageFile) { string extension = ".jpg"; string fileName = i + extension; addmodel.ImageUrl = uploadFullPath + endString + "/" + fileName; //sciezka zapisu zdjecia fileName = Path.Combine(Server.MapPath("/Uploads/" + endString), fileName); pp.SaveAs(fileName); i++; } return(RedirectToAction("Index", "Home", null)); } else { ModelState.AddModelError( string.Empty, "Wprowadzone dane są nieprawidłowe."); return(View(addmodel)); } }
public void AddPost(PostModels post) { if (ModelState.IsValid) { string postTo; if (string.IsNullOrWhiteSpace(post.PostToId)) { postTo = User.Identity.GetUserId(); } else { postTo = post.PostToId; } PostModels postModel = new PostModels() { Text = post.Text, PostFromId = User.Identity.GetUserId(), PostToId = postTo, PostDateTime = DateTime.Now }; postRepository.Add(postModel); postRepository.Save(); } }
public async Task <IActionResult> Create([FromBody] CreatePostRequest postRequest) { var newPost = new Post { Name = postRequest.Name, UserId = HttpContext.GetUserId() }; newPost.Id = Guid.NewGuid(); Post result = await _postRepository.Add(newPost); if (result == null) { return(BadRequest()); } var response = new PostResponse { Id = result.Id, Name = result.Name }; string urlBase = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}"; string locationUri = $"{urlBase}/{ApiRoutes.Posts.Get.Replace("{postId}", newPost.Id.ToString())}"; return(Created(locationUri, response)); }
public bool CreatePost(POST post) { bool returnValue = false; post.CREATED_DATE = DateTime.Now; returnValue = postRepo.Add(post); return(returnValue); }
public void AddPostCorrectly() { var post = new Post(new User("Tony"), new Tweet("Hello there!")); _postRepository.Add(post); CollectionAssert.Contains(_postRepository.GetPosts(), post); }
public IActionResult Post(Post post) { var currentUser = GetCurrentUserProfile(); post.UserProfileId = currentUser.Id; _postRepository.Add(post); return(CreatedAtAction("Get", new { id = post.Id }, post)); }
public bool Add(string Title, string Caption, string TimeDate, int ID_User, int Visible = 1) { post.Title = Title; post.Caption = Caption; post.TimeDate = TimeDate; post.ID_User = ID_User; post.Visible = Visible; return(postRepository.Add(post)); }
public ActionResult Create(Post post, int competition) { var lstImage = new List <string>(); HttpFileCollectionBase files = Request.Files; if (files.Count > 5) { return(Json(new { result = false, mess = "Do not upload larger than 5 images" })); } Task task = Task.Run(async() => { for (int i = 0; i < files.Count; i++) { HttpPostedFileBase file = files[i]; Account account = new Account("dev2020", "247996535991499", "9jI_5YjJaseBKUrY929sUtt0Fy0"); string path = Path.Combine(Server.MapPath("Images"), Path.GetFileName(file.FileName)); Cloudinary cloudinary = new Cloudinary(account); var uploadParams = new ImageUploadParams() { File = new FileDescription(path, file.InputStream), }; var uploadResult = await cloudinary.UploadAsync(uploadParams); lstImage.Add(uploadResult.SecureUrl.ToString()); } }); task.Wait(); var userID = User.Identity.GetUserId(); post.Id = userID; post.CompetitionId = competition; var commpettion = _competitionRepository.Find(x => x.CompetitionId == post.CompetitionId); if (commpettion == null || commpettion.EndDate < DateTime.Now) { return(Json(new { result = false, mess = "Competition has ended, No new additions allowed" })); } post.Images = string.Join(";", lstImage); post.CreatedTime = DateTime.Now; post.UpdatedTime = DateTime.Now; post.Mark = 0; post.IsPaid = true; post.PriceCustomer = 800; post.IsSold = true; post.Published = true; var result = _postRepository.Add(post); if (result > 0) { return(Json(new { result = true, mess = "Create Success", url = "/Admin/Post/Index" })); } return(Json(new { result = false, mess = "Create not Success", url = "/Admin/Post/Index" })); }
// public void InsertPost(string text) { Post post = new Post(); post.Text = text; post.PostOwnerId = userRepository.GetUserId(userServices.NickNameRead()); post.Date = DateTime.Now.ToString(); repository.Add(post); }
public void FindCommentTest() { //arrange var userModel = new UserModel() { Name = "Pepa Hnátek", LastLogged = DateTime.Today, MailAddress = "*****@*****.**" }; var userRepository = new UserRepository(dbContextFactory, mapper); userModel = userRepository.Add(userModel); var teamModel = new TeamModel { Description = "Tym resici ics", Name = "Borci" }; var teamRepository = new TeamRepository(dbContextFactory, mapper); teamModel = teamRepository.Add(teamModel); teamRepository.AddUserToTeam(teamModel.Id, userModel.Id); var postModel = new PostModel { Title = "Hlava", Author = userModel, Text = "Ztratil jsem hlavu!", TimeCreated = DateTime.Now, Team = teamModel }; var postRepository = new PostRepository(dbContextFactory, mapper); postModel = postRepository.Add(postModel); var comment1 = new CommentModel { Author = userModel, ParentPost = postModel, Text = "Hledej, dìlej!!", TimeCreated = DateTime.Now }; var commentRepository = new CommentRepository(dbContextFactory, mapper); commentRepository.Add(comment1); //act var commentsShouldBeFound = commentRepository.FindByText("dìlej", teamModel); var commentsShouldNotBeFound = commentRepository.FindByText("alohomora", teamModel); //assert Assert.NotEmpty(commentsShouldBeFound); Assert.Empty(commentsShouldNotBeFound); teamRepository.Remove(teamModel.Id); //should remove also the post and comment userRepository.Remove(userModel.Id); Assert.Null(postRepository.getById(postModel.Id)); }
public IActionResult Post(Post post) { int userId = GetCurrentUserProfile().Id; post.UserProfileId = userId; _postRepository.Add(post); post.IsApproved = false; return(CreatedAtAction("Get", new { id = post.Id }, post)); }
public void AddCommentTest() { var userRepository = new UserRepository(dbContextFactory, mapper); var teamRepository = new TeamRepository(dbContextFactory, mapper); var userModel = new UserModel { Name = "Pepa Hnátek", LastLogged = DateTime.Today, MailAddress = "*****@*****.**" }; var teamModel = new TeamModel { Description = "Tym resici ics", Name = "Borci" }; userModel = userRepository.Add(userModel); teamModel = teamRepository.Add(teamModel); teamRepository.AddUserToTeam(teamModel.Id, userModel.Id); userModel = userRepository.GetById(userModel.Id); teamModel = teamRepository.GetById(teamModel.Id); var postRepository = new PostRepository(dbContextFactory, mapper); var commentRepository = new CommentRepository(dbContextFactory, mapper); var postModel = new PostModel { Title = "Hlava", Author = userModel, Text = "Ztratil jsem hlavu!", TimeCreated = DateTime.Now, Team = teamModel }; postModel = postRepository.Add(postModel); var commentModel = new CommentModel { Text = "Tak ji zase najdi.", TimeCreated = DateTime.Now, Author = userModel, ParentPost = postModel }; commentModel = commentRepository.Add(commentModel); //assert Assert.Equal("Tak ji zase najdi.", commentRepository.getById(commentModel.Id).Text); Assert.Equal("Tak ji zase najdi.", postRepository.getById(postModel.Id).Comments.First().Text); teamRepository.Remove(teamModel.Id); //should remove also the post and comment userRepository.Remove(userModel.Id); Assert.Null(postRepository.getById(postModel.Id)); Assert.Null(commentRepository.getById(commentModel.Id)); }
public async Task <IActionResult> Post(Post post) { var currentUser = await GetCurrentUser(); post.UserProfileId = currentUser.Id; post.DateCreated = DateTime.Now; _postRepository.Add(post); return(CreatedAtAction("Get", new { id = post.Id }, post)); }
public ActionResult Create(Post post) { if (ModelState.IsValid) { PostRepository.Add(post); return(RedirectToAction("Index")); } return(View(post)); }
public HttpResponseMessage Post(Post post) { post.PublishDate = DateTime.Now; repository.Add(post); var response = Request.CreateResponse <Post>(HttpStatusCode.Created, post); string uri = Url.Link("DefaultApi", new { id = post.ID }); response.Headers.Location = new Uri(uri); return(response); }
public IActionResult Post(Post post) { var currentUserProfile = GetCurrentUserProfile(); post.UserProfileId = currentUserProfile.Id; post.DateCreated = DateTime.Now; _postRepository.Add(post); return(CreatedAtAction(nameof(Get), new { id = post.Id }, post)); }
public ActionResult Create(PostVM post) { if (ModelState.IsValid) { var usuarioDomain = Mapper.Map <PostVM, Post>(post); _postRepository.Add(usuarioDomain); return(RedirectToAction("Index")); } return(View(post)); }
public void InsertMockarooData() { var postRepository = new PostRepository(); var jsonList = ReadMockarooFile(); foreach (var jsonPost in jsonList) { var post = mapper.Map <Post>(jsonPost); postRepository.Add(post); } }
public ActionResult Create([Bind(Include = "PostID,PostName,PostTime")] Post post) { if (ModelState.IsValid) { repository.Add(post); repository.SaveChanges(); return(RedirectToAction("Index")); } return(View(post)); }
public IActionResult Add(Post item) { if (ModelState.IsValid) { repository.Add(item); return(RedirectToAction("Index")); } else { return(View("Index")); } }
public void CreatePost(PostViewModel postViewModel) { var post = new Post { Body = postViewModel.Body, PostData = postViewModel.PostData, Price = postViewModel.Price, PostType = postViewModel.PostType }; _postRepository.Add(post); }
public void Add(PostModel postModel) { if (!string.IsNullOrWhiteSpace(postModel.PostToId)) { // Get current user id(the poster) string currentUser = User.Identity.GetUserId(); // Convert to PostModel PostModel saveModel = new PostModel { Id = postModel.Id, PostFromId = currentUser, Message = postModel.Message, PostDateTime = DateTime.Now, PostToId = postModel.PostToId }; // Add to database and save changes. postRepository.Add(saveModel); postRepository.Save(); } else { // Get current user id(the poster) string currentUser = User.Identity.GetUserId(); // Convert to PostModel PostModel saveModel = new PostModel { Id = postModel.Id, PostFromId = currentUser, Message = postModel.Message, PostDateTime = DateTime.Now, PostToId = currentUser }; // Add to database and save changes. postRepository.Add(saveModel); postRepository.Save(); } }
private static void CreatePost(string title, string content, string slug, string datePublished, int authorID) { var result = PostRepository.Get(slug); DateTime?published = null; if (result != null) { throw new HttpException(409, "Slug already in use"); } if (!string.IsNullOrWhiteSpace(datePublished)) { published = DateTime.Parse(datePublished); } PostRepository.Add(title, content, slug, published, authorID); }