public async Task <IActionResult> AddForum(AddForumModel model) { var imageUri = "/images/users/default.png"; if (model.ImageUpload != null && model.ImageUpload.Length != 0) { //var blockBlob = UploadForumImage(model.ImageUpload); //imageUri = blockBlob.Uri.AbsoluteUri; string pathRoot = _environment.WebRootPath; string path_to_Images = pathRoot + "\\Images\\forum\\" + model.ImageUpload.FileName; using (var stream = new FileStream(path_to_Images, FileMode.Create)) { await model.ImageUpload.CopyToAsync(stream); } imageUri = "/Images/forum/" + model.ImageUpload.FileName; } var forum = new Forum { Title = model.Title, Descripition = model.Description, Created = DateTime.Now, ImageUrl = imageUri }; await _forumService.Create(forum); return(RedirectToAction("Index", "Forum")); }
public async Task AddPostShouldAddAPostWithTheGivenInputModelAndReturnPostId() { int defaultLikes = 0; var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("forumTest"); var db = new ApplicationDbContext(options.Options); var topic = "TestTopic"; var text = "TestText"; var newInputAdd = new AddForumModel() { Topic = topic, Text = text, }; var countBeforeAdding = db.Forums.Count(); var service = new ForumsService(db); var postId = await service.AddPost(newInputAdd); var postDb = db.Forums.FirstOrDefault(f => f.ForumId == postId); Assert.Equal(countBeforeAdding + 1, db.Forums.Count()); Assert.NotNull(postDb); Assert.Equal(defaultLikes, postDb.Likes); }
public async Task <IActionResult> AddForum(AddForumModel model) { //set default image for the new forums var imageUri = "/images/users/default.png"; if (model.ImageUpload != null) { var blockBlob = UploadForumImage(model.ImageUpload); imageUri = blockBlob.Uri.AbsoluteUri; } var forum = new Forum { Id = model.ForumId, Title = model.Title, Description = model.Description, Created = DateTime.Now, ImageUrl = imageUri }; if (forum.Id > 0) { await _forumService.UpdateForum(forum); } else { await _forumService.Create(forum); } return(RedirectToAction("Index", "Forum")); }
public async Task <IActionResult> AddForum(AddForumModel model) { var imageUri = ""; if (model.ImageUpload != null) { var blockBlob = PostForumImage(model.ImageUpload); imageUri = blockBlob.Uri.AbsoluteUri; } else { imageUri = "/images/users/default.png"; } var forum = new Data.Models.Forum() { Title = model.Title, Description = model.Description, Created = DateTime.Now, ImageUrl = imageUri, GroupId = model.GroupId }; if (forum.Description != null && forum.Title != null) { await _forumService.Add(forum); } return(RedirectToAction("ChosenGroupAsync", "Group", new { id = model.GroupId })); }
public async Task <IActionResult> AddForum(AddForumModel model) { var imageUri = ""; if (model.ImageUpload != null) { var blockBlob = PostForumImage(model.ImageUpload); imageUri = blockBlob.Uri.AbsoluteUri; } else { imageUri = "/images/users/default.png"; } var forum = new Data.Models.Forum() { Title = model.Title, Description = model.Description, Created = DateTime.Now, ImageUrl = imageUri }; await _forumService.Add(forum); return(RedirectToAction("Index", "Forum")); }
public async Task <IActionResult> AddForum(AddForumModel model) { var imageUrl = ""; if (model.ImageUrl == null) { var forum = new Forum { Title = model.Title, Description = model.Description, Created = DateTime.Now, ImageUrl = imageUrl }; await _forumService.Create(forum); } else { var forum = new Forum { Title = model.Title, Description = model.Description, Created = DateTime.Now, ImageUrl = model.ImageUrl }; await _forumService.Create(forum); } return(RedirectToAction("Index", "Forum")); }
public async Task <IActionResult> EditForum(AddForumModel model) { var imageUri = model.ImageUrl; if (model.ImageUrl == "") { imageUri = "/images/users/default.png"; } if (model.ImageUpload != null && model.ImageUpload.Length != 0) { //var blockBlob = UploadForumImage(model.ImageUpload); //imageUri = blockBlob.Uri.AbsoluteUri; string pathRoot = _environment.WebRootPath; string path_to_Images = pathRoot + "\\Images\\forum\\" + model.ImageUpload.FileName; using (var stream = new FileStream(path_to_Images, FileMode.Create)) { await model.ImageUpload.CopyToAsync(stream); } imageUri = "/Images/forum/" + model.ImageUpload.FileName; } model.ImageUrl = imageUri; await _forumService.UpdateForum(model.Id, model.Title, model.Description, model.ImageUrl); return(RedirectToAction("index")); }
public IActionResult Create() { //Create a empty model and pass it to the view var model = new AddForumModel(); return(View(model)); }
public IActionResult Create() { var model = new AddForumModel { }; return(View(model)); }
public IActionResult Create(string Id) { var model = new AddForumModel { GroupId = Id }; return(View(model)); }
public IActionResult Create() { if (User.IsInRole("Admin")) { var model = new AddForumModel(); return(View(model)); } else { return(Redirect("/")); } }
public async Task <IActionResult> AddForum(AddForumModel model) { var forum = new Forum { Title = model.Title, Description = model.Description, CreatedTime = DateTime.Now }; await _forumService.Create(forum); return(RedirectToAction("Index", "Forum")); }
public IActionResult Edit(int id) { var forum = _forumService.GetById(id); var model = new AddForumModel { Id = forum.Id, Title = forum.Title, Description = forum.Descripition, ImageUrl = forum.ImageUrl }; return(View(model)); }
public async Task <IActionResult> AddForum(AddForumModel model) { var imageUri = "/images/users/default.png"; var forum = new Forum { Title = model.Title, Description = model.Description, Created = DateTime.Now, ImageUrl = imageUri }; await _forumService.Create(forum); return(RedirectToAction("Index", "Forum")); }
public async Task <IActionResult> AddForum(AddForumModel input) { if (!this.User.Identity.IsAuthenticated) { return(this.Redirect("/Identity/Account/Login")); } var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); string forumId = await this.forumsService.AddPost(input); await this.forumsService.AddPostToUser(userId, forumId); return(this.Redirect("/RP/Forum")); }
public async Task <string> AddPost(AddForumModel input) { if (input == null) { throw new ArgumentNullException("input", "The given input is null!"); } var post = new Forum() { ForumText = input.Text, ForumTopic = input.Topic, Likes = 0, }; await this.db.Forums.AddAsync(post); await this.db.SaveChangesAsync(); return(post.ForumId); }
public async Task <IActionResult> AddForum(AddForumModel model) { var imageUri = "/images/forum/forum.png"; if (model.file != null) { imageUri = await UploadForumImage(model.file); } var forum = new Forum() { Title = model.Title, Description = model.Description, Created = DateTime.Now, ImageUrl = imageUri }; await _forumService.Create(forum); return(RedirectToAction("Index", "Forum")); }
public async Task <IActionResult> AddForum(AddForumModel model) { var imageUri = "/images/users/default.png"; if (model.ImageUpload != null) { var uri = await uploadService.UploadImage(model.ImageUpload /*, $"Forum-Logos/{model.Title}"*/); imageUri = uri.AbsoluteUri; } var forum = new Forum { Title = model.Title, Description = model.Description, Created = DateTime.Now, ImageUrl = imageUri }; await forumService.Create(forum); return(RedirectToAction("Index", "Forum")); }
public async Task <IActionResult> AddForum(AddForumModel model) { var imageUri = "/images/ico/bibliomit.svg"; if (model?.ImageUpload != null) { imageUri = UploadForumImage(model.ImageUpload); } var forum = new Forum { Title = model.Title, Description = model.Description, Created = DateTime.Now, ImageUrl = new Uri(imageUri) }; await _forumService.Create(forum).ConfigureAwait(false); return(RedirectToAction("Index", "Fora")); }
public async Task <IActionResult> AddForum(AddForumModel model) { var imageUri = "/images/forum/default.png"; if (model.ImageUpload != null) { string uploadImage = SaveUploadImage(model.ImageUpload); imageUri = uploadImage; } var forum = new Forum { Title = model.Title, Description = model.Description, Created = DateTime.Now, ImageUrl = imageUri }; await _forumService.Create(forum); return(RedirectToAction("Index", "Forum")); }
public async Task <IActionResult> AddForum(AddForumModel model) { var imageUri = "/images/forum/forum.png"; //if (model.ImageUpload != null) //{ // var blocBlob = UploadForumImage(model.ImageUpload); // imageUri = blocBlob.Uri.AbsoluteUri; //} var forum = new Forum { Title = model.Title, Description = model.Description, Created = DateTime.Now, ImageUrl = imageUri }; await _forum.Create(forum); return(RedirectToAction("Index", "Forum")); }
public async Task <ActionResult> AddForum(AddForumModel model) { var imageUri = "/images/default.png"; if (model.ImageUpload != null) { imageUri = "/images/forum/" + model.ImageUpload.FileName; var path = Server.MapPath("~" + imageUri); model.ImageUpload.SaveAs(path); } var forum = new MyForum { Title = model.Title, Description = model.Description, Created = DateTime.Now, ImageUrl = imageUri }; await _myForumService.Create(forum); return(RedirectToAction("Index", "Forum")); }
public async Task <IActionResult> AddForum(AddForumModel model) { if (model.ImageUpload != null) { var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images\\forum", model.ImageUpload.FileName); using (var stream = new FileStream(path, FileMode.Create)) { await model.ImageUpload.CopyToAsync(stream); } } var forum = new Forumm { Title = model.Title, Description = model.Description, Created = DateTime.Now, ImageUrl = "/images/forum/" + model.ImageUpload.FileName }; await _forumService.Create(forum); return(RedirectToAction("Index", "Forum")); }
public async Task <IActionResult> AddForum(AddForumModel model) { var imageDefaultUri = "images/default.png"; if (model.ImageUpload != null) { //upload forum image file imageDefaultUri = this.uploadService.UploadImageForum(model.ImageUpload); } var forum = new Forum() { Title = model.Title, Description = model.Description, Created = DateTime.Now, ImageUrl = imageDefaultUri }; await this.forumService.Create(forum); return(RedirectToAction("Index", "Forum")); }
public IActionResult Create(int?forumId) { if (forumId.HasValue) { var forum = _forumService.GetById((int)forumId); var model = new AddForumModel { ForumId = forum.Id, Title = forum.Title, Description = forum.Description, ImageUrl = forum.ImageUrl }; return(View(model)); } else { var model = new AddForumModel(); return(View(model)); } }
public async Task <IActionResult> AddForum(AddForumModel model) { var imageUri = "/images/users/default.png"; if (model.ImageUpload != null) { var blockBlob = UploadForumImage(model.ImageUpload); imageUri = blockBlob.Uri.AbsoluteUri; } var forum = new Forum { Judul = model.Judul, Deskripsi = model.Deskripsi, Dibuat = DateTime.Now, ImageUrl = imageUri }; await _forumService.Create(forum); return(RedirectToAction("Index", "Forum")); }
public async Task <IActionResult> AddForum(AddForumModel model, IFormCollection image1) { string storePath = "/images/forum/"; var path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot", "images", "forum", image1.Files[0].FileName); using (var stream = new FileStream(path, FileMode.Create)) { await image1.Files[0].CopyToAsync(stream); } var forum = new Forum { Title = model.Title, Description = model.Description, Created = DateTime.Now, ImageUrl = storePath + model.ImageUpload.FileName }; await _forumService.Create(forum); return(RedirectToAction("Index", "Forum")); }
public async Task <IActionResult> AddForum(AddForumModel model) { var imageUri = "/images/users/default.png"; if (model.ImageUpload != null) { var blockBlob = UploadForumImage(model.ImageUpload); imageUri = blockBlob.Uri.AbsoluteUri; } var forum = new Forum { Title = model.Title, Description = model.Description, Created = DateTime.Now, BookOrder = model.BookOrder, OldOrNew = model.OldOrNew, ImageUrl = imageUri }; await _forumService.Create(forum); return(RedirectToAction("Index", "Forum")); }
public async Task <IActionResult> AddForum(AddForumModel model, IFormFile UploadImage, IFormFile UploadVideo, IFormFile UploadFile) { var imageUri = ""; var videoUri = ""; var fileUri = ""; if (model.UploadImage != null) { var contentDisposition = ContentDispositionHeaderValue.Parse(UploadImage.ContentDisposition); var fileName = contentDisposition.FileName.Trim('"'); var pathHost = _host.WebRootPath; var parsePath = pathHost.Replace('\\', '/'); var path = pathHost + $"/images/forum/{User.Identity.Name}/" + fileName; imageUri = $"/images/forum/{User.Identity.Name}/" + fileName; using (var fileStream = new FileStream(path, FileMode.Create)) { await UploadImage.CopyToAsync(fileStream); } } else { imageUri = "/images/forum/default.png"; } if (model.UploadVideo != null) { var contentDisposition = ContentDispositionHeaderValue.Parse(UploadVideo.ContentDisposition); var fileName = contentDisposition.FileName.Trim('"'); var pathHost = _host.WebRootPath; var parsePath = pathHost.Replace('\\', '/'); var path = pathHost + $"/images/forum/{User.Identity.Name}/" + fileName; videoUri = $"/images/forum/{User.Identity.Name}/" + fileName; using (var fileStream = new FileStream(path, FileMode.Create)) { await UploadVideo.CopyToAsync(fileStream); } } else { videoUri = "/images/forum/default.mp4"; } if (model.UploadFile != null) { var contentDisposition = ContentDispositionHeaderValue.Parse(UploadFile.ContentDisposition); var fileName = contentDisposition.FileName.Trim('"'); var pathHost = _host.WebRootPath; var parsePath = pathHost.Replace('\\', '/'); var path = pathHost + $"/images/forum/{User.Identity.Name}/" + fileName; fileUri = $"/images/forum/{User.Identity.Name}/" + fileName; using (var fileStream = new FileStream(path, FileMode.Create)) { await UploadFile.CopyToAsync(fileStream); } } else { fileUri = "/images/forum/default.xlsx"; } var forum = new Forum { Title = model.Title, Description = model.Description, VideoUrl = videoUri, ImageUrl = imageUri, FileUrl = fileUri, Path = User.Identity.Name, Value = model.Value, Comment = model.Comment, DateCreate = DateTime.Now, DateFinish = model.DateFinish }; await _forumService.Add(forum); return(RedirectToAction("Index", "Forum", forum)); }
public IActionResult Create(int id) { var model = new AddForumModel(); return(View(model)); }