コード例 #1
0
        public ActionResult Transition_GaleriResimSil(string id)
        {
            int albume_id = 0;

            try
            {
                int gimage_id = Convert.ToInt32(id);

                akgul_yemek_dbEntities db     = new akgul_yemek_dbEntities();
                gallery_images         gimage = db.gallery_images.Where(w => w.id == gimage_id).FirstOrDefault();
                if (gimage != null)
                {
                    albume_id = gimage.title_id;

                    string content_type = (gimage.file_name.Contains(".")) ? "image" : "video";

                    if (content_type == "image")
                    {
                        //deleting picture from disk
                        string file_path = Path.Combine(Server.MapPath("~/Files/Galleries/" + albume_id), gimage.file_name);
                        if (System.IO.File.Exists(file_path))
                        {
                            System.IO.File.Delete(file_path);
                        }
                    }
                    else if (content_type == "video")
                    {
                        // not need to anything
                    }

                    // deleting from database
                    db.gallery_images.Remove(gimage);
                    db.SaveChanges();

                    Session["message"] = new MessageModel("Bilgi", "Fotoğraf/Video Silindi.", Message_Type.Success);
                    return(RedirectToAction("Galeri_Detay", new { id = "" + albume_id }));
                }
                else
                {
                    MLog.Error("Fotoğraf/Video Silinemedi.", "Belirtilen Fotoğraf/Video Bulunamadı.");
                    Session["message"] = new MessageModel("HATA", "Belirtilen Fotoğraf Bulunamadı.", Message_Type.Error);

                    return(RedirectToAction("Galeri_Detay"));
                }
            }
            catch (Exception exception)
            {
                MLog.Error("Fotoğraf Silinemedi.", exception.Message + Environment.NewLine + exception.StackTrace);
                Session["message"] = new MessageModel("HATA", "Bir hata oluştu.", Message_Type.Error);
                return(RedirectToAction("Galeri_Listele"));
            }
        }
コード例 #2
0
        public ActionResult Transition_GaleriResimEkle(FormCollection formCollection)
        {
            int random_number = new Random().Next(0, 1024);
            int albume_id     = 0;

            try
            {
                ext_gallery_images g_image = (ext_gallery_images)MTranslation.BuildObject(formCollection, "ext_gallery_images");
                albume_id = g_image.title_id;

                // adding picture to Disk
                HttpPostedFileBase file = Request.Files[0];
                if (file.ContentLength > 0 && g_image.title_id > 0)
                {
                    string filename = Path.GetFileName(file.FileName);
                    string path     = Path.Combine(Server.MapPath("~/Files/Galleries/" + albume_id), "" + random_number + filename);
                    file.SaveAs(path);

                    // food image_name is uploaded picture name
                    g_image.file_name = "" + random_number + filename;


                    gallery_images save_gimage = new gallery_images()
                    {
                        file_name = g_image.file_name,
                        title_id  = g_image.title_id
                    };

                    // adding food to Database
                    akgul_yemek_dbEntities db = new akgul_yemek_dbEntities();
                    db.gallery_images.Add(save_gimage);
                    db.SaveChanges();

                    Session["message"] = new MessageModel("Bilgi", "Fotoğraf Galeriye Ekendi.", Message_Type.Success);
                    return(RedirectToAction("Galeri_Detay", new { id = "" + albume_id }));
                }
                else if (g_image.videoUrl != "")
                {
                    string videoCode = g_image.videoUrl.Split('=')[1];

                    gallery_images save_gimage = new gallery_images()
                    {
                        file_name = videoCode,
                        title_id  = g_image.title_id
                    };

                    // adding food to Database
                    akgul_yemek_dbEntities db = new akgul_yemek_dbEntities();
                    db.gallery_images.Add(save_gimage);
                    db.SaveChanges();

                    Session["message"] = new MessageModel("Bilgi", "Video Galeriye Ekendi.", Message_Type.Success);
                    return(RedirectToAction("Galeri_Detay", new { id = "" + albume_id }));
                }
                else
                {
                    MLog.Error("Fotoğraf/Video Galeriye Ekenemedi.", "Eksik Bilgi Girildi.");
                    Session["message"] = new MessageModel("HATA", "Eksik Bilgi Girildi.", Message_Type.Error);

                    return(RedirectToAction("Galeri_Detay", new { id = "" + albume_id }));
                }
            }
            catch (Exception exception)
            {
                MLog.Error("Fotoğraf Galeriye Ekenemedi.", exception.Message + Environment.NewLine + exception.StackTrace);
                Session["message"] = new MessageModel("HATA", "Bir hata oluştu.", Message_Type.Error);

                return(RedirectToAction("Galeri_Listele"));
            }
        }