示例#1
0
        public async Task <ActionResult> Index(ArticleViewModel articleViewModel)
        {
            if (articleViewModel.File != null && articleViewModel.File.ContentLength > 0)
            {
                try
                {
                    var article = CreateArticle(articleViewModel);
                    article.ArticlePath = Path.Combine(Server.MapPath("~/Articles"),
                                                       Path.GetFileName(articleViewModel.File.FileName));

                    articleViewModel.File.SaveAs(article.ArticlePath);
                    ViewBag.Message = "File uploaded successfully";
                    await articleWriteRepository.AddArticle(article);

                    await searchService.DoIndexation(article);

                    await signatureService.DoIndexation(article);

                    return(RedirectToAction("Index", "Load"));
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "ERROR:" + ex.Message.ToString();
                }
            }
            else
            {
                ViewBag.Message = "You have not specified a file.";
            }
            return(View());
        }