Ejemplo n.º 1
0
 public static DBO.ArticleImage GetArticleImageByArticle(long article_id)
 {
     try
     {
         using (MeditateBookEntities bdd = new MeditateBookEntities())
         {
             T_Article_Image ArticleImage = bdd.T_Article_Image.Where(x => x.id_article == article_id).First();
             if (ArticleImage != null)
             {
                 DBO.ArticleImage newAttach = new DBO.ArticleImage()
                 {
                     Id        = ArticleImage.id,
                     IdArticle = ArticleImage.id_article,
                     ImagePath = ArticleImage.image_path,
                     Name      = ArticleImage.name
                 };
                 return(newAttach);
             }
             return(null);
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e);
         return(null);
     }
 }
Ejemplo n.º 2
0
        public static List <DBO.ArticleImage> GetListWithWord(string word)
        {
            List <DBO.ArticleImage> result = new List <DBO.ArticleImage>();

            try
            {
                using (MeditateBookEntities bdd = new MeditateBookEntities())
                {
                    List <T_Article_Image> list = bdd.T_Article_Image.Where(x => x.name.ToLower().Contains(word)).ToList();
                    foreach (T_Article_Image ArticleImage in list)
                    {
                        DBO.ArticleImage newAttach = new DBO.ArticleImage()
                        {
                            Id        = ArticleImage.id,
                            IdArticle = ArticleImage.id_article,
                            ImagePath = ArticleImage.image_path,
                            Name      = ArticleImage.name
                        };
                        result.Add(newAttach);
                    }
                    return(result);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                return(result);
            }
        }
Ejemplo n.º 3
0
 public static bool CreateArticleImage(DBO.ArticleImage articleImage)
 {
     try
     {
         using (MeditateBookEntities bdd = new MeditateBookEntities())
         {
             T_Article_Image newArticleAttach = new T_Article_Image()
             {
                 id_article = articleImage.IdArticle,
                 image_path = articleImage.ImagePath,
                 name       = articleImage.Name
             };
             bdd.T_Article_Image.Add(newArticleAttach);
             bdd.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e);
         return(false);
     }
 }
Ejemplo n.º 4
0
 public static bool UpdateArticleImage(DBO.ArticleImage articleImage)
 {
     try
     {
         using (MeditateBookEntities bdd = new MeditateBookEntities())
         {
             T_Article_Image old = bdd.T_Article_Image.Where(x => x.id == articleImage.Id).FirstOrDefault();
             if (old != null)
             {
                 old.id_article = articleImage.IdArticle;
                 old.image_path = articleImage.ImagePath;
                 old.name       = articleImage.Name;
                 bdd.SaveChanges();
                 return(true);
             }
             return(false);
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e);
         return(false);
     }
 }
Ejemplo n.º 5
0
 public static bool CreateArticleImage(DBO.ArticleImage articleImage)
 {
     return(DataAccess.ArticleImage.CreateArticleImage(articleImage));
 }
Ejemplo n.º 6
0
        public ActionResult EditArticle(EditArticleModel model, HttpPostedFileBase file)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var result = true;

            switch (result)
            {
            case true:
                DBO.Article article = new DBO.Article {
                    Title = model.Title, Content = model.Content, Validated = false, CreatedDate = DateTime.Now
                };
                var idCreator = HttpContext.Session["UserID"];
                if (idCreator != null)
                {
                    article.IdCreator = (long)idCreator;
                }
                BusinessManagement.Article.CreateArticle(ref article);

                if (file != null)
                {
                    string pic  = System.IO.Path.GetFileName(file.FileName);
                    string dir  = Server.MapPath("~/images/article");
                    string path = System.IO.Path.Combine(dir, pic);

                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }

                    // file is uploaded
                    file.SaveAs(path);
                    DBO.ArticleImage image = new DBO.ArticleImage();
                    image.ImagePath = path;
                    image.Name      = pic;
                    image.IdArticle = article.Id;
                    BusinessManagement.ArticleImage.CreateArticleImage(image);
                }
                string dirAttach = Server.MapPath("~/images/attach");
                int    i         = 0;
                if (HttpContext.Session["ListAttach" + i] != null)
                {
                    while (HttpContext.Session["ListAttach" + i] != null)
                    {
                        DBO.ArticleAttach articleAttach = new DBO.ArticleAttach();
                        articleAttach.Name      = (string)HttpContext.Session["ListAttach" + i];
                        articleAttach.FilePath  = Path.Combine(dirAttach, articleAttach.Name);
                        articleAttach.IdArticle = article.Id;
                        BusinessManagement.ArticleAttach.CreateArticleAttach(articleAttach);
                        i++;
                    }
                }


                return(RedirectToAction("Submit", "Articles"));

            case false:
                ModelState.AddModelError("", "Insertion d'article invalide");
                return(View(model));

            default:
                ModelState.AddModelError("", "Insertion d'article invalide");
                return(View(model));
            }
        }