public void AddTagsToPost(string tags, Post post) { if (!string.IsNullOrEmpty(tags) && tags.Contains(',') && post != null) { foreach (string tagName in tags.Split(',')) { Tag newTag; string tagText = GenFunx.CleanStringForUse(tagName.ToLower()); try { newTag = db.Tags.Where(t => t.TagText == tagText).First(); } catch (Exception) { newTag = new Tag() { TagText = tagName }; db.Tags.Add(newTag); db.SaveChanges(); } PostTag newPostTag = new PostTag() { PostID = post.PostID, TagID = newTag.TagID }; db.PostTags.Add(newPostTag); } db.SaveChanges(); } }
public ActionResult ImageUpload(HttpPostedFileBase denemeDosyasi) { bool isUploaded = false; string uploadedFilePath = GenFunx.ImageUpload(denemeDosyasi, "ProfilePictures", out isUploaded); if (isUploaded) { isUploaded = false; Image thumb = GenFunx.ResizeImage(uploadedFilePath, new Size() { Height = 100, Width = 100 }); string uploadedThumbPath = GenFunx.ImageUpload(thumb, "Thumbnails", uploadedFilePath.Split('/').Last(), out isUploaded); if (isUploaded) { ViewBag.Resim = uploadedFilePath; ViewBag.Thumb = uploadedThumbPath; } else { ViewBag.Sonuc = uploadedThumbPath; } } else { ViewBag.Sonuc = uploadedFilePath; } return(View()); }
public ActionResult NewChannel(Channel newChannel, HttpPostedFileBase imgChannelProfilePicture, HttpPostedFileBase imgChannelCoverPicture) { if (imgChannelProfilePicture != null) { bool isUploaded = false; string uploadedFilePath = GenFunx.ImageUpload(imgChannelProfilePicture, "~/Content/Images/ChannelPictures", out isUploaded); if (isUploaded) { isUploaded = false; Image thumbImage = GenFunx.ResizeImage(uploadedFilePath, new Size() { Height = 200, Width = 200 }); string uploadedThumbPath = GenFunx.ImageUpload(thumbImage, "~/Content/Images/Thumbnails", uploadedFilePath.Split('/').Last(), out isUploaded); if (isUploaded) { newChannel.ChannelProfilePicture = uploadedFilePath.Split('/').Last(); } } } if (imgChannelCoverPicture != null) { bool isUploaded = false; string uploadedCoverPath = GenFunx.ImageUpload(imgChannelCoverPicture, "~/Content/Images/ChannelCovers", out isUploaded); if (isUploaded) { isUploaded = false; Image thumbCover = GenFunx.ResizeImage(uploadedCoverPath, new Size() { Height = 200, Width = 256 }); string uploadedThumbPath = GenFunx.ImageUpload(thumbCover, "~/Content/Images/Thumbnails", uploadedCoverPath.Split('/').Last(), out isUploaded); if (isUploaded) { newChannel.ChannelCoverPicture = uploadedCoverPath.Split('/').Last(); } } } if (cr.InsertChannel(newChannel, out string islemSonucu)) { return(RedirectToAction("ViewChannels")); } else { ViewBag.Hata = islemSonucu; return(View()); } }
public ActionResult VideoUpload(HttpPostedFileBase denemeDosyasi) { string uploadedVideo = GenFunx.VideoUpload(denemeDosyasi, "~/Content/Videos/Temporary", out bool isUploaded); string relocatedVideo = GenFunx.RelocateVideo(uploadedVideo, out bool isCopied); if (isCopied) { ViewBag.Sonuc = relocatedVideo; } else { ViewBag.Sonuc = "Bir sorun oluştu: " + uploadedVideo + " " + relocatedVideo; } return(View()); }
public ActionResult EditChannel(Channel chToUp, HttpPostedFileBase imgChannelProfilePicture, HttpPostedFileBase imgChannelCoverPicture) { chToUp.CreateTime = DateTime.Now; chToUp.User = Session["user"] as User; if (imgChannelProfilePicture != null) { bool isUploaded = false; string uploadedFilePath = GenFunx.ImageUpload(imgChannelProfilePicture, "~/Content/Images/ChannelPictures", out isUploaded); if (isUploaded) { isUploaded = false; Image thumbImage = GenFunx.ResizeImage(uploadedFilePath, new Size() { Height = 200, Width = 200 }); string uploadedThumbPath = GenFunx.ImageUpload(thumbImage, "~/Content/Images/Thumbnails", uploadedFilePath.Split('/').Last(), out isUploaded); if (isUploaded) { chToUp.ChannelProfilePicture = uploadedFilePath.Split('/').Last(); } } else { ViewBag.Hata = "Profil resmi karşıya yüklenemedi"; return(View()); } } if (imgChannelCoverPicture != null) { bool isUploaded = false; string uploadedCoverPath = GenFunx.ImageUpload(imgChannelCoverPicture, "~/Content/Images/ChannelCovers", out isUploaded); if (isUploaded) { isUploaded = false; Image thumbCover = GenFunx.ResizeImage(uploadedCoverPath, new Size() { Height = 200, Width = 256 }); string uploadedThumbPath = GenFunx.ImageUpload(thumbCover, "~/Content/Images/Thumbnails", uploadedCoverPath.Split('/').Last(), out isUploaded); if (isUploaded) { chToUp.ChannelCoverPicture = uploadedCoverPath.Split('/').Last(); } } else { ViewBag.Hata = "Kapak resmi karşıya yüklenemedi"; return(View()); } } if (cr.EditChannel(chToUp, out string islemSonucu)) { return(RedirectToAction("ViewChannels")); } else { ViewBag.Hata = islemSonucu; return(View(chToUp)); } }
public List <Tag> GetTagsWithText(string tagText) { tagText = GenFunx.CleanStringForUse(tagText.ToLower()); return(db.Tags.Where(t => t.TagText.Contains(tagText)).ToList()); }
public ActionResult NewPost(HttpPostedFileBase video, Post newPost, int channelID, string postTags) { try { ChannelRepo cr = new ChannelRepo(); PostRepo pr = new PostRepo(); VideoRepo vr = new VideoRepo(); User currentUser = Session["user"] as User; if (cr.IsUserOwnerOfChannel(currentUser.UserID, channelID)) { if (newPost != null && !(string.IsNullOrEmpty(newPost.PostTitle)) && video != null) { string uploadedVideo = GenFunx.VideoUpload(video, "~/Content/Videos/Temporary", out bool isUploaded); if (isUploaded) { string relocatedVideo = GenFunx.RelocateVideo(uploadedVideo, out bool isCopied); if (isCopied) { string thumbnailPath = GenFunx.GetThumbnailFromVideo(relocatedVideo, out bool isDone); if (isDone) { newPost.ChannelID = channelID; newPost.PostThumbnailPath = thumbnailPath.Split('/').Last(); bool sonuc = pr.InsertPost(newPost, out string islemSonucu); if (sonuc) { Video newVideo = GenFunx.GetVideoFromMediaFile(relocatedVideo); //TODO: Farklı boyutlara convert etme işlemi burada olacak. relocatedVideo işle işlem yapılacak. //TODO: Transaction yapısı include edilecek newVideo.PostID = newPost.PostID; bool vidOK = vr.InsertVideo(newVideo, out islemSonucu); if (vidOK) { ViewBag.Sonuc = "Yeni video başarıyla yüklendi"; pr.AddTagsToPost(postTags, newPost); } else { ViewBag.Sonuc = "Video yüklenirken hata oldu: " + islemSonucu; } } else { ViewBag.Sonuc = "Kayıt sırasında bir hata meydana geldi: " + islemSonucu; } } else { ViewBag.Sonuc = "Küçük resim alındamadı: " + thumbnailPath; } } else { ViewBag.Sonuc = "Yükleme sırasında bir hata oluştu: " + relocatedVideo; } } else { ViewBag.Sonuc = "Yükleme sırasında bir hata oluştu: " + uploadedVideo; } } else { ViewBag.Sonuc = "Video nesnesi veya başlığı boş bırakılamaz"; } } else { ViewBag.Sonuc = "Bu kanalı kullanarak video yükleyemezsiniz"; } } catch (Exception ex) { ViewBag.Sonuc = ex.Message; } return(View()); }