public async Task<IActionResult> Post([FromBody] PostAddViewModel postAddViewModel) { if (postAddViewModel == null) return BadRequest(); if (!ModelState.IsValid) return new MyUnprocessableEntityObjectResult(ModelState); var newPost = _mapper.Map<PostAddViewModel, Post>(postAddViewModel); newPost.Author = "admin"; newPost.LastModified = DateTime.Now; _postRepository.AddPost(newPost); if(!await _unitOfWork.SaveAsync()) { throw new Exception("Save Failed!"); } var resultViewModel = _mapper.Map<Post, PostViewModel>(newPost); var links = CreateLinkForPost(newPost.Id); var linkedPostViewModel = resultViewModel.ToDynamic() as IDictionary<string, object>; linkedPostViewModel.Add("links" , links); return CreatedAtRoute("GetPost" , new { id = linkedPostViewModel ["Id"]} , linkedPostViewModel); }
public IActionResult Add(PostAddViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } var post = new Post { Title = viewModel.Title, Body = viewModel.Body, CategoryId = viewModel.CategoryId, ApplicationUserId = viewModel.ApplicationUserId, ImageUrl = GetImageFilePath(viewModel.ImageUpload) }; var result = _postRepository.AddPost(post); if (result == true) { TempData["StatusMessage"] = "Post added successfully!"; } else { ModelState.AddModelError(string.Empty, "Oops, something went wrong, please try again!"); } return(RedirectToAction("Add")); }
public async Task <IActionResult> Add(PostAddViewModel postAddViewModel) { if (ModelState.IsValid) { var postAddDto = Mapper.Map <PostAddDto>(postAddViewModel); var imageResult = await ImageHelper.Upload(postAddViewModel.Title, postAddViewModel.ThumbnailFile, PictureType.Post); postAddDto.Thumbnail = imageResult.Data.FullName; var result = await _postService.AddAsync(postAddDto, LoggedInUser.UserName, LoggedInUser.Id); if (result.ResultStatus == ResultStatus.Success) { _toastNotification.AddSuccessToastMessage(result.Message, new ToastrOptions { Title = "Başarılı İşlem!" }); return(RedirectToAction("Index", "Post")); } else { ModelState.AddModelError("", result.Message); } } var categories = await _categoryService.GetAllByNoneDeletedAndActiveAsync(); postAddViewModel.Categories = categories.Data.Categories; return(View(postAddViewModel)); }
public IActionResult Add(PostAddViewModel model) { if (ModelState.IsValid) { // Create new Post to add database var post = new Post { ImageUrl = UploadPostImage(model.Image), Title = model.Title, PostContent = model.PostContent, NumberOfClicks = 0, AddedDate = model.AddedDate, CategoryId = model.CategoryId, UserId = model.UserId }; _postService.Add(post); TempData["Message"] = "Yeni paylaşım başarıyla eklendi !"; TempData["MessageState"] = "warning"; return(RedirectToAction("Posts", "Admin")); } TempData["Message"] = "Paylaşım eklenirken bir hata oluştu !"; TempData["MessageState"] = "danger"; return(RedirectToAction("Posts", "Admin")); }
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 ActionResult Add() public ActionResult Add() { var viewModel = new PostAddViewModel(); viewModel.Init(_tagRepository, _categoryRepository); return(View(viewModel)); }
public ActionResult Create() { ViewBag.UserId = new SelectList(_context.Users, "Id", "Email"); PostAddViewModel postmodel = new PostAddViewModel() { }; return(View(postmodel)); }
public PostAddViewModel PopulateDropDown() { var viewModel = new PostAddViewModel(); var categories = _categoryRepository.GetAll(); var users = _userRepository.GetAllUsers(); viewModel.Categories = categories; viewModel.Users = users; return(viewModel); }
public ActionResult AddTag(PostAddViewModel viewModel) { var post = viewModel.Post; var tag = new PostTags { PostId = post.Id, TagId = viewModel.TagId }; _postTagsRepository.Add(tag); return(RedirectToAction("Edit", new { id = post.Id })); }
public ActionResult Add() { var model = new PostAddViewModel() { Post = new Post(), Categories = _categoryService.GetList(), Authors = _authorService.GetList() }; return(View(model)); }
public IActionResult Add() { var categories = _categoryService.GetAll(); var model = new PostAddViewModel { Categories = categories, AddedDate = DateTime.Now, UserId = Convert.ToInt32(User.FindFirstValue(ClaimTypes.NameIdentifier)) }; return(View(model)); }
public ActionResult AddPost(PostAddViewModel model) { if (!ModelState.IsValid) { return(Redirect("/Post/Posts/" + model.CourseId)); } this.postService.Add(new Post { Content = model.Content, CourseId = model.CourseId, Date = DateTime.Now, UserId = this.User.Identity.GetUserId() }); return(Redirect("/Post/Posts/" + model.CourseId)); }
public IActionResult Add(PostAddViewModel model) { if (ModelState.IsValid) { Post post = new Post { Title = model.Title, Text = model.Text, PublishDate = model.PublishDate, IsPublished = model.IsPublished, BackwardPostId = model.BackwardPostId, ForwardPostId = model.ForwardPostId, ResourceLinks = model.ResourceLinks, RelatedPosts = ProcessAndGetRelatedPosts(0, model.RelatedPosts), }; post.TagsLink = new List <PostsTags>(); if (model.Tags != null) { foreach (Tag tag in model.Tags) { Tag newTag = tagRepo.GetByText(tag.Text); post.TagsLink.Add(new PostsTags { Post = post, Tag = newTag ?? new Tag { Text = tag.Text } }); } } postRepo.Add(post); } return(View()); }
public ActionResult Add(PostAddViewModel viewModel) { ValidatePost(viewModel.Post); if (ModelState.IsValid) { var post = viewModel.Post; _postRepository.Add(post); _postTagsRepository.Add(new PostTags { PostId = post.Id, TagId = viewModel.TagId }); TempData["Message"] = "Your post was successfully added."; return(RedirectToAction("Details", new { id = post.Id })); } viewModel.Init(_tagRepository, _categoryRepository); return(View(viewModel)); }
public async Task <IHttpActionResult> Add_Post(PostAddViewModel model) { if (!string.IsNullOrWhiteSpace(model.accountusername)) { var Db = new ApplicationDbContext(); string uname = RequestContext.Principal.Identity.GetUserName(); var user = Db.Users.Where(x => x.UserName == uname).FirstOrDefault(); if (user != null) { var account = user.accounts.Where(x => x.username == model.accountusername && x.accounttype == AccountsEnum.Instagram).FirstOrDefault(); if (account != null) { var postmodel = new ScheduledPost() { id = Guid.NewGuid().ToString(), type = model.type, datetime = DateTime.FromBinary(long.Parse(model.date)), post = Convert.FromBase64String(model.data) }; account.ScheduledPosts.Add(postmodel); var result = await Db.SaveChangesAsync(); if (result == 1) { return(Ok()); } else { return(new System.Web.Http.Results.ExceptionResult(new Exception(result.ToString()), this)); } } else { return(new System.Web.Http.Results.ExceptionResult(new Exception("No Account"), this)); } } return(new System.Web.Http.Results.ExceptionResult(new Exception("No user"), this)); } return(new System.Web.Http.Results.ExceptionResult(new Exception("No user"), this)); }
public PostAddPage() { InitializeComponent(); _viewModel = new PostAddViewModel(); BindingContext = _viewModel; }