예제 #1
0
        public ActionResult AddArticle(Article ar)
        {
            ar = (Article)ModelHelper.ModelSupplement(ar);
            ViewBag.ArticleCategory = GetAllCategoryForDLL(ar.category_id).AsEnumerable();
            foreach (string upload in Request.Files.AllKeys)
            {
                HttpPostedFileBase excelFile = Request.Files["article_cover_image"];

                if (excelFile.ContentLength > 0)
                {
                    DateTime now        = DateTime.Now;
                    string   newDirPath = string.Format(@"{0}\{1}\{2}\", Server.MapPath("../"), "Upload", now.ToString(@"yyyy\\mm\\dd"));
                    string   newUrlPath = string.Format("/{0}/{1}/", "Upload", now.ToString("yyyy/mm/dd"));
                    string   newPath    = Path.Combine(Server.MapPath(@"..\"), "Upload", "");
                    string   fileName   = now.ToFileTime().ToString() + excelFile.FileName.Substring(excelFile.FileName.LastIndexOf('.'));
                    ar.article_cover_image = newUrlPath + fileName;
                    if (!Directory.Exists(newDirPath))
                    {
                        Directory.CreateDirectory(newDirPath);
                    }
                    excelFile.SaveAs(newDirPath + fileName);
                }
            }
            ar.article_kuser = Session["user_id"].ToString();
            ar.article_muser = Session["user_id"].ToString();
            if (ModelState.IsValid)
            {
                ArticleBll articleBll = new ArticleBll();
                articleBll.AddArticle(ar);
            }

            return(Redirect("index"));
        }
        private void HandleAddArticle(NetworkStream stream)
        {
            try
            {
                Console.WriteLine("Client adding article");
                Utils.SendObject(Constants.Success, stream);
                var articleUpdateDto = Utils.ReadObject <ArticleUpdateDto>(stream);
                var article          = MapToArticle(articleUpdateDto);
                _articleBll.AddArticle(article);
                Utils.SendObject(Constants.Success, stream);

                Console.WriteLine("Successfully added article");

                NotifyObservers();
            }
            catch (Exception e)
            {
                Utils.SendObject(Constants.Error, stream);
            }
        }