Пример #1
0
        public static List <DBO.ArticleAttach> GetListArticleAttachByArticle(long article_id)
        {
            List <DBO.ArticleAttach> result = new List <DBO.ArticleAttach>();

            try
            {
                using (MeditateBookEntities bdd = new MeditateBookEntities())
                {
                    List <T_Article_Attach> list = bdd.T_Article_Attach.Where(x => x.id_article == article_id).ToList();
                    foreach (T_Article_Attach ArticleAttach in list)
                    {
                        DBO.ArticleAttach newAttach = new DBO.ArticleAttach()
                        {
                            Id        = ArticleAttach.id,
                            IdArticle = ArticleAttach.id_article,
                            FilePath  = ArticleAttach.file_path,
                            Name      = ArticleAttach.name
                        };
                        result.Add(newAttach);
                    }
                    return(result);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                return(result);
            }
        }
Пример #2
0
 public static bool CreateArticleAttach(DBO.ArticleAttach articleAttach)
 {
     try
     {
         using (MeditateBookEntities bdd = new MeditateBookEntities())
         {
             T_Article_Attach newArticleAttach = new T_Article_Attach()
             {
                 id_article = articleAttach.IdArticle,
                 file_path  = articleAttach.FilePath,
                 name       = articleAttach.Name
             };
             bdd.T_Article_Attach.Add(newArticleAttach);
             bdd.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e);
         return(false);
     }
 }
Пример #3
0
 public static bool UpdateArticleAttach(DBO.ArticleAttach articleAttach)
 {
     try
     {
         using (MeditateBookEntities bdd = new MeditateBookEntities())
         {
             T_Article_Attach old = bdd.T_Article_Attach.Where(x => x.id == articleAttach.Id).FirstOrDefault();
             if (old != null)
             {
                 old.id_article = articleAttach.IdArticle;
                 old.file_path  = articleAttach.FilePath;
                 old.name       = articleAttach.Name;
                 bdd.SaveChanges();
                 return(true);
             }
             return(false);
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e);
         return(false);
     }
 }
Пример #4
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));
            }
        }
Пример #5
0
 public static bool CreateArticleAttach(DBO.ArticleAttach articleAttach)
 {
     return(DataAccess.ArticleAttach.CreateArticleAttach(articleAttach));
 }