private async void BtnSubmit_OnClicked(object sender, EventArgs e) { AddPost addPost = new AddPost() { ImageURL = imageUrl, Size = pickerSize.Items[pickerSize.SelectedIndex], Color = pickerColor.Items[pickerColor.SelectedIndex], Material = pickerMaterialType.Items[pickerMaterialType.SelectedIndex] }; await App.MobileService.GetTable <AddPost>().InsertAsync(addPost); await DisplayAlert("Success", "Upload successful", "OK"); /* Using SQLite DB on local machine * using (SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation)) * { * conn.CreateTable<AddPost>(); * int rows = conn.Insert(addPost); * conn.Close(); * * if (rows > 0) * { * await DisplayAlert("Success", "Upload successful", "OK"); * } * else * { * await DisplayAlert("Error", "Upload failed", "OK"); * } * } */ }
public void Execute(AddPost request) { _validator.ValidateAndThrow(request); var post = new Domain.Post { UserId = request.UserId, Name = request.Name, Description = request.Description, IsDeleted = false, CreatedAt = DateTime.Now, ModifidedAt = null }; if (Context.Posts.Any(p => p.Name == request.Name)) { throw new EntityAllreadyExists("Post"); } Context.Posts.Add(post); try { Context.SaveChanges(); return; } catch (Exception) { throw; } }
public void AddPostTest() { AddPost article = new AddPost(driver); article.UploadArticle(); // Assert.IsTrue(driver.FindElement(By.XPath("//img[@class='_s0 _4ooo _1x2_ _1ve7 _1gax img']")).Displayed); }
public IActionResult UpdateQuestion(int id, [FromBody] AddPost addPost) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Post obj = _postRepository.GetById(id); if (obj == null) { return(NotFound("Post not found")); } obj.Audio = addPost.Audio; obj.Body = addPost.Body; obj.Document = addPost.Document; obj.Image = addPost.Image; obj.Video = addPost.Video; var postObj = _mapper.Map <Post>(addPost); _postRepository.Update(obj, postObj); return(Ok("Post updated successfully")); }
public IActionResult AddPost([FromBody] JObject data) { string LoginUserIdentifier = GetUserAuth0ID(); string ConnStr = GetDbConnString(); AddPost addPost = data["AddPost"].ToObject <AddPost>(); using (IDbConnection db = new SqlConnection(ConnStr)) { string SqlStr = @"insert into SM_Posts values (@Auth0IDAuthor, @PostGuid, @DateCreated, @PostContent, @DisableSharing, @DisableComments) insert into SM_Posts_File_Urls values (@PostGuid, @FileUrl, @FileType, @TempTagList) "; int result = db.Execute(SqlStr, new { Auth0IDAuthor = LoginUserIdentifier, PostGuid = addPost.PostGuid, DateCreated = addPost.DateCreated, PostContent = addPost.PostContent, FileUrl = addPost.FileUrl, FileType = addPost.FileType, TempTagList = addPost.TempTagList, DisableSharing = "", DisableComments = "" } ); } return(Ok()); }
public async Task SaveAddPost(IPrincipal user, AddPost post) { var AppUser = await _manager.FindByNameAsync(user.Identity.Name); var userId = AppUser.Id; var userName = AppUser.UserName; if (post.Id == 0) { //var newDate = new DateTime.; //var netDate = newDate.toISOString(); var newPost = new AddPost { UserId = userId, UserName = userName, Title = post.Title, Location = post.Location, Price = post.Price, //Date = newDate, Discription = post.Discription }; _repo.Add <AddPost>(newPost); _repo.SaveChanges(); } else { _repo.Update(post); } }
public void Execute(AddPost request) { _validator.ValidateAndThrow(request); var potDto = Context.Posts.Find(request); if (potDto != null) { try { potDto.Name = request.Name; potDto.UserId = request.UserId; potDto.IsDeleted = false; potDto.Description = request.Description; potDto.ModifidedAt = DateTime.Now; Context.SaveChanges(); } catch (Exception) { throw new Exception(); } } else { throw new EntityNotFoundException(potDto.Id, typeof(AddPost)); } }
private void AddPost(object sender, RoutedEventArgs e) { AddPost window = new AddPost() { WindowStartupLocation = WindowStartupLocation.CenterScreen }; window.Show(); }
public IActionResult AddPost(AddPost addPost) { if (ModelState.IsValid) { db.AddPostToTag(addPost.Name, addPost.Id); return(RedirectToAction(addPost.Id, "Tags")); } return(RedirectToAction(addPost.Id, "Tags")); }
public AddPostViewModel(AddPost addPost, tblUser userLogedIn) { view = addPost; postService = new PostService(); Post = new tblPost(); User = userLogedIn; }
public async Task Update(AddPost entity) { try { await unitOfWork.GetConnection().QueryAsync(UpdateSql, entity, unitOfWork.GetTransaction()); } catch (Exception ex) { throw ex; } }
public JsonResult AddPost(AddPost addPostModel, int userID) { var user = repository.Users.FindByCondition(u => u.ID == userID).FirstOrDefault(); var postToInsert = repository.Posts.Create(new Post { User = null, Type = addPostModel.Type, Platform = addPostModel.Platform, Position = addPostModel.Position, PlayerRating = addPostModel.PlayerRating, Description = addPostModel.Description, CreatedAt = DateTime.Now }); repository.Save(); _logger.LogInformation("Post created"); return(new JsonResult("Post Created!")); }
public async Task <string> TestControl([FromForm] AddPost post) { using (var db = new DbConnection()) { await db.Connection.OpenAsync(); var query = new TestDBWorker(db); await query.AddTest(post.subject, post.name, post.questionsInTest, post.questionsAll, post.resultOfQuestion, post.mixAnswers, post.mixQuestions, post.notAnsweredForbidden, post.json); return("added"); } }
public IActionResult AddQuestion([FromBody] AddPost addPost) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var postObj = _mapper.Map <Post>(addPost); _postRepository.Add(postObj); _postRepository.SaveChanges(); //return CreatedAtAction("GetPostById", new { id = addPost.Id }, addPost); return(Ok("Post created")); }
public async Task <int> Add(AddPost entity) { try { var id = await unitOfWork.GetConnection().QuerySingleAsync <int>(AddSql, entity, unitOfWork.GetTransaction()); return(id); //return new Guid(); } catch (Exception ex) { throw ex; } }
private void AddPostExecute() { try { AddPost addPost = new AddPost(User); addPost.ShowDialog(); PostList = postService.GetPosts(); ListDto = ConvertListToDtoList(PostList); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public ActionResult DeleteConfirmed(int id) { if (Session["UserID"] != null) { AddPost addPost = db.addPost.Find(id); db.addPost.Remove(addPost); db.SaveChanges(); return(RedirectToAction("Index")); } else { return(RedirectToAction("Login", "Account")); } }
public async Task <IActionResult> OnGet(string boardKey, Guid threadId, Guid replyTo, CancellationToken cancellationToken) { EnsureArg.IsNotEmpty(threadId, nameof(threadId)); var t = await this.threadService.GetThread(threadId, Constants.PageSize, cancellationToken).ConfigureAwait(false); return(t.Match(thread => { this.IsAdmin = this.isAdmin.IsAdmin(this.HttpContext); this.Thread = thread; var newComm = replyTo == Guid.Empty ? string.Empty : $">>{replyTo}\n"; this.Post = new AddPost(threadId, this.cookieStorage.ReadName(this.Request), string.Empty, newComm, null); return Page().ToIAR(); }, () => this.NotFound().ToIAR())); }
public async Task <AddPost> Add(AddPost entity) { try { var addedId = await productRepository.Add(entity); var result = await productRepository.GetById(addedId.ToString()); return(result); } catch (Exception ex) { throw new RestException(System.Net.HttpStatusCode.NotFound, ex.Message); } }
public IActionResult Post([FromBody] AddPost dto, [FromServices] ICreatePostCommand command) { try { executor.ExecuteCommand(command, dto); return(StatusCode(201, "Succesfully added a new post.")); } catch (EntityNotFoundException e) { if (e.Message == "Product not found.") { return(NotFound(e.Message)); } return(UnprocessableEntity(e.Message)); } }
public Task <AddPost> Update(AddPost entity) { return(Task.FromResult(entity)); //try //{ // if (entity.Password == string.Empty) // throw new Exception("Id can not be null"); // await productRepository.Update(entity); // var product = await productRepository.GetById(entity.Id.ToString()); // return product; //} //catch (Exception ex) //{ // throw new RestException(System.Net.HttpStatusCode.NotFound, ex.Message); //} }
public IActionResult Put(int id, [FromBody] AddPost dto, [FromServices] IEditPostCommand command) { try { dto.Id = id; executor.ExecuteCommand(command, dto); return(StatusCode(204, "Succesfully edited a post")); } catch (EntityNotFoundException e) { if (e.Message == "Product not found.") { return(NotFound(e.Message)); } return(UnprocessableEntity(e.Message)); } }
public void AddPost_Test() { // arrange mockRepo.Setup(repo => repo.Posts.FindByCondition(u => u.ID == It.IsAny <int>())).Returns(GetPosts()); mockRepo.Setup(repo => repo.Users.FindByCondition(u => u.ID == It.IsAny <int>())).Returns(GetUsers()); AddPost potentialPost = new AddPost() { Type = "Looking for player", Platform = "PS5", PlayerRating = "87", Position = "RW", Description = "test description" }; // act var controllerJsonResult = postController.AddPost(potentialPost, 2); // assert Assert.NotNull(controllerJsonResult); Assert.IsType <JsonResult>(controllerJsonResult); }
public ViewResult AddPost() { var list = _categoryRepository.GetAll().Select(c => new SelectListItem { Text = c.CategoryName, Value = c.CategoryID.ToString() } ).ToList(); list.Insert(0, new SelectListItem { Text = "Please Select...", Value = string.Empty }); AddPost model = new AddPost(); model.CategoriesList = list; return(View(model)); }
public ActionResult Edit([Bind(Include = "PostID,Title,Description,Datum,UserID,CategoryID")] AddPost addPost) { if (Session["UserID"] != null) { if (ModelState.IsValid) { addPost.UserID = Convert.ToInt32(Session["UserID"]); db.Entry(addPost).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryID = new SelectList(db.category, "CategoryID", "Name", addPost.CategoryID); ViewBag.UserID = new SelectList(db.userAccount, "UserID", "FirstName", addPost.UserID); return(View(addPost)); } else { return(RedirectToAction("Login", "Account")); } }
// GET: Post/Details/5 public ActionResult Details(int?id) { if (Session["UserID"] != null) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AddPost addPost = db.addPost.Find(id); if (addPost == null) { return(HttpNotFound()); } return(View(addPost)); } else { return(RedirectToAction("Login", "Account")); } }
public IActionResult AddPost(Post post) { if (!ModelState.IsValid) { AddPost model = new AddPost(); model.CategoriesList = _categoryRepository.GetAll().Select(c => new SelectListItem { Text = c.CategoryName, Value = c.CategoryID.ToString() } ); return(View(model)); } else { post.PostDate = DateTime.Now; _postRepository.Add(post); return(RedirectToAction("Index")); } }
// GET: Post/Edit/5 public ActionResult Edit(int?id) { if (Session["UserID"] != null) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AddPost addPost = db.addPost.Find(id); if (addPost == null) { return(HttpNotFound()); } ViewBag.CategoryID = new SelectList(db.category, "CategoryID", "Name", addPost.CategoryID); ViewBag.UserID = new SelectList(db.userAccount, "UserID", "FirstName", addPost.UserID); return(View(addPost)); } else { return(RedirectToAction("Login", "Account")); } }
public IActionResult Post([FromForm] AddPost p) { var ext = Path.GetExtension(p.Image.FileName); if (!FileUpload.AllowedExtensions.Contains(ext)) { return(UnprocessableEntity("Image extension is not allowed.")); } try { var newFileName = Guid.NewGuid().ToString() + "_" + p.Image.FileName; var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images", newFileName); p.Image.CopyTo(new FileStream(filePath, FileMode.Create)); var post = new InsertPostDto { Name = p.Name, FileName = newFileName, Text = p.Text, CategoryId = p.CategoryId, UserId = p.UserId, }; _addPost.Execute(post); return(StatusCode(201)); } catch (EntityAlredyExists) { return(NotFound()); } catch (Exception e) { return(StatusCode(500, "An error has occured.")); } }
public ActionResult Put(int id, [FromForm] AddPost p) { var ext = Path.GetExtension(p.Image.FileName); if (!FileUpload.AllowedExtensions.Contains(ext)) { return(UnprocessableEntity("Image extension is not allowed.")); } try { var newFileName = Guid.NewGuid().ToString() + "_" + p.Image.FileName; var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploads", newFileName); p.Image.CopyTo(new FileStream(filePath, FileMode.Create)); var post = new UpdatePostDto { Id = p.Id, Name = p.Name, Text = p.Text, Pictures = newFileName }; _editPost.Execute(post); return(StatusCode(201)); } catch (EntityNoFound n) { return(NotFound()); } catch (Exception e) { return(StatusCode(500, "An error has occured.")); } }
private void addPostButton_click(object sender, EventArgs e) { AddPost addPost = new AddPost(); addPost.ShowDialog(); }