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 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 static int AddForum(ForumInfo forum) { if (forum == null) { return(-1); } IForum dal = Factory <IForum> .Create("Forum"); return(dal.Add(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)); }