Exemplo n.º 1
0
        public ActionResult Add(Article data, HttpPostedFileBase Image)
        {
            List <string> UploadedImagePaths = new List <string>();

            UploadedImagePaths = ImageUploader.UploadSingleImage(ImageUploader.OriginalProfileImagePath, Image, 1);

            data.ImagePath = UploadedImagePaths[0];

            if (data.ImagePath == "0" || data.ImagePath == "1" || data.ImagePath == "2")
            {
                data.ImagePath = ImageUploader.DefaultProfileImagePath;
                data.ImagePath = ImageUploader.DefaultXSmallProfileImage;
                data.ImagePath = ImageUploader.DefaulCruptedProfileImage;
            }
            else
            {
                data.ImagePath = UploadedImagePaths[1];
                data.ImagePath = UploadedImagePaths[2];
            }

            data.Status      = Core.Enum.Status.Active;
            data.PublishDate = DateTime.Now;
            _articleService.Add(data);
            return(Redirect("/Admin/Article/List"));
        }
Exemplo n.º 2
0
        public ActionResult Add(Article data, HttpPostedFileBase Image)
        {
            List <string> UploadedImagePaths = new List <string>();

            UploadedImagePaths = ImageUploader.UploadSingleImage(ImageUploader.OriginalProfileImagePath, Image, 1);

            data.ImagePath = UploadedImagePaths[0];

            if (data.ImagePath == "0" || data.ImagePath == "1" || data.ImagePath == "2")
            {
                data.ImagePath = ImageUploader.DefaultProfileImagePath;
                data.ImagePath = ImageUploader.DefaultXSmallProfileImage;
                data.ImagePath = ImageUploader.DefaulCruptedProfileImage;
            }
            else
            {
                data.ImagePath = UploadedImagePaths[1];
                data.ImagePath = UploadedImagePaths[2];
            }
            AppUser user = _appUserService.GetByDefault(x => x.UserName == User.Identity.Name);

            data.AppUserID   = user.ID;
            data.PublishDate = DateTime.Now;

            _articleService.Add(data);
            return(Redirect("/Author/Article/List"));
        }
Exemplo n.º 3
0
        public JsonResult Add(ArticleViewModel model)
        {
            ResultRetrun rmodel = new ResultRetrun();

            if (ModelState.IsValid)
            {
                Account account   = GetAccount();
                Article downModel = new Article()
                {
                    Title       = model.Title,
                    Content     = !string.IsNullOrEmpty(model.Description) ? model.Description.Replace("\r\n", "") : string.Empty,
                    Category    = model.Category,
                    State       = (PublishState)model.State,
                    HeadImg     = model.HeadImg,
                    ParCategory = model.ParCategory,
                    UserId      = account.Id,
                    Section     = model.Section,
                    Author      = account.UserName
                };

                rmodel.isSuccess = articleService.Add(downModel);
            }

            return(Json(rmodel));
        }
Exemplo n.º 4
0
        public ActionResult AddArticle(Article model, HttpPostedFileBase file)
        {
            if (file != null)
            {
                string displayName     = Path.GetFileName(file.FileName);
                var    uploadDirection = Path.Combine(Server.MapPath("~/Content/img"), displayName);
                file.SaveAs(uploadDirection);
                model.ImagePath = displayName;

                if (ModelState.IsValid)
                {
                    TempData["durum"] = "Kayıt başarılı!";

                    model.UserID = userDb.GetByName(HttpContext.User.Identity.Name).ID;
                    db.Add(model);
                    return(View());
                }
            }
            else
            {
                TempData["durum"] = "Kayıt Başarısız oldu!";
            }


            return(View());
        }
Exemplo n.º 5
0
        public void TestAdd()
        {
            mockArticleRepository.Setup(x => x.Add(It.IsAny <Article>())).Returns(article);
            var     _articleService = new ArticleService(mockArticleRepository.Object);
            Article articleReturn   = _articleService.Add(article);

            Assert.IsNotNull(articleReturn);
        }
Exemplo n.º 6
0
        public IActionResult Post([FromBody] ArticleRequestBody body)
        {
            var article = articleService.Add(body.MapTo <ArticleToAddOrUpdate>());

            return(this.CreateHalResponse(article.MapTo <ArticleResponseBody>())
                   .AddLink(LinkTemplates.Article.Self)
                   .AddLocationHeader(this, article.Id)
                   .ToActionResult(this, HttpStatusCode.Created));
        }
        public IActionResult Create([FromForm] CreateArticleViewModel viewModel)
        {
            string imageDirectory = Path.Combine(webHostEnvironment.WebRootPath, "ArticleImage");

            try
            {
                if (ModelState.IsValid == false)
                {
                    return(View(viewModel));
                }
                if (authorService.DoesAuthorExist(viewModel.Email))
                {
                    tagService.AddMultipleTags(viewModel.ArticleTags);
                    var tags = tagService.GetForArticleFromString(viewModel.ArticleTags);
                    articleService.Add(viewModel.Title,
                                       viewModel.Content,
                                       viewModel.Email,
                                       viewModel.Image,
                                       imageDirectory,
                                       tags);
                    return(RedirectToAction("Index"));
                }
                if (viewModel.DoesAuthorExist == true)
                {
                    viewModel.DoesAuthorExist = false;
                    return(View(viewModel));
                }
                tagService.AddMultipleTags(viewModel.ArticleTags);
                var myTags = tagService.GetForArticleFromString(viewModel.ArticleTags);
                authorService.Add(viewModel.Email, viewModel.FirstName, viewModel.LastName);
                articleService.Add(viewModel.Title,
                                   viewModel.Content,
                                   viewModel.Email,
                                   viewModel.Image,
                                   imageDirectory,
                                   myTags);
                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Exemplo n.º 8
0
        public void Add_WhenCalled_AddsArticle()
        {
            // Arrange
            var article = new Mock <Article>();

            // Act
            service.Add(article.Object);

            // Assert
            repository.Verify(x => x.Add(article.Object));
        }
Exemplo n.º 9
0
 public IActionResult Add([FromBody] Article article)
 {
     try
     {
         _articleService.Add(article);
         return(Created($"{Request.Path}/{article.Number}", article));
     }
     catch (InvalidOperationException)
     {
         return(Conflict());
     }
 }
 public ActionResult <Result <Article> > Post([FromBody] Article model)
 {
     try
     {
         model.createdUserId = Current.user.id;
         _articleService.Add(model);
         _logger.LogInformation("Added one Article");
         return(new Result <Article>(true, "Article added successfully"));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, "Error occurred on Article adding");
         throw ex;
     }
 }
Exemplo n.º 11
0
 public IActionResult OnPost(
     [FromServices] UserManager <ApplicationUser> userManager,
     [FromServices] ArticleService service,
     int?categoryId)
 {
     ViewData["Success"] = false;
     try
     {
         var userId = userManager.GetUserId(User);
         service.Add(Input.Title, Input.Content, categoryId, userId);
         ViewData["Success"] = true;
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("error", "¼ì²éÊäÈë");
     }
     return(Page());
 }
Exemplo n.º 12
0
        public ActionResult ArticleAdd(Article article, HttpPostedFileBase Image)
        {
            List <string> UploadedImagePaths = new List <string>();

            UploadedImagePaths = ImageUploader.UploadSingleImage(ImageUploader.OriginalImageProfilePath, Image, 1);
            article.ImagePath  = UploadedImagePaths[0];
            if (article.ImagePath == "0" || article.ImagePath == "1" || article.ImagePath == "2")
            {
                article.ImagePath = ImageUploader.DefaultProfileImagePath;
                article.ImagePath = ImageUploader.DefaultXSmallProfileImagePath;
                article.ImagePath = ImageUploader.DefaultCruptedImagesProfileImagePath;
            }
            AppUser user = _appUserService.GetByDefault(x => x.UserName == HttpContext.User.Identity.Name);

            article.AppUserID = user.ID;
            _articleService.Add(article);
            TempData["Başarılı"] = "Successful";
            return(Redirect("/Author/Article/ArticleList"));
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string action = Request["action"];

            if (action == "Edit")
            {
                long    id  = Convert.ToInt64(Request["id"]);
                Article art = articleService.GetById(id);
                art.Title = txtTitle.Text;
                art.Msg   = txtMsg.Text;

                // 更新数据库
                articleService.Update(art);

                // 更新索引库
                IndexTask task = new IndexTask();
                task.TaskId = id;
                IndexManager.Instance.UpdateArticle(task);

                Response.Redirect("ArticleList.aspx");
            }
            else if (action == "AddNew")
            {
                Article art = new Article();
                art.Title = txtTitle.Text;
                art.Msg   = txtMsg.Text;

                // 更新数据库
                art = articleService.Add(art);

                // 更新索引库
                IndexTask task = new IndexTask();
                task.TaskId = art.Id;
                IndexManager.Instance.AddArticle(task);

                Response.Redirect("ArticleList.aspx");
            }
            else
            {
                throw new Exception("action错误!");
            }
        }
Exemplo n.º 14
0
        void addButton_Click(object sender, EventArgs e)
        {
            try
            {
                String  ArtNo       = ArtNoTextBox.Text;
                String  Name        = NameTextBox.Text;
                String  Description = DescriptionTextBox.Text;
                Decimal Price       = Decimal.Parse(PriceTextBox.Text, Thread.CurrentThread.CurrentCulture.NumberFormat);
                int     Quant       = Int32.Parse(QuantTextBox.Text);

                _logger.Debug("addButton_Click -> begin");
                _logger.Debug("addButton_Click -> ArtNo=" + ArtNo);
                _logger.Debug("addButton_Click -> Name=" + Name);
                _logger.Debug("addButton_Click -> Description=" + Description);
                _logger.Debug("addButton_Click -> Price=" + Price);
                _logger.Debug("addButton_Click -> Quant=" + Quant);

                var article = ArticleService.Add(ArtNo, Name, Description, Price, Quant);

                MessageBox.Show(article.GetName() + " erfolgreich hinzugefügt");
                ResetFields();
                LoadArticles();
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show("Ungültige Eingabe");
            }
            catch (FormatException ex)
            {
                MessageBox.Show("Ungültige Eingabe");
            }
            catch (Exception ex1)
            {
                MessageBox.Show(ex1.Message);
            }
        }
Exemplo n.º 15
0
 public ActionResult Add(Article Data)
 {
     _articleService.Add(Data);
     return(Redirect("/Admin/Article/List"));
 }
Exemplo n.º 16
0
        public JsonResult Add(string articleId, string title, string content, string htmlContent, List <int> lables, string keyWords, string urlTitle, string editor)
        {
            try
            {
                AddValidate(articleId, title, content, urlTitle);

                //新增
                if (string.IsNullOrEmpty(articleId))
                {
                    Article article = new Article();
                    article.Title       = title;
                    article.Content     = content;
                    article.HtmlContent = htmlContent;
                    article.KeyWords    = keyWords;
                    article.UrlTitle    = urlTitle;
                    article.Editor      = Convert.ToInt32(editor);
                    articleId           = _articleService.Add(article).ToString();

                    try
                    {
                        if (lables != null)
                        {
                            foreach (var item in lables)
                            {
                                _articleLabelService.Add(int.Parse(articleId), item);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        LogService.Instance.AddAsync(Level.Error, ex);
                        return(Json(new { code = 503, msg = "文章保存成功,标签保存失败" }));
                    }
                }
                else //编辑
                {
                    var model = _articleService.GetById(articleId);

                    //如果权限控制只能处理自已的数据的话
                    if (_permissionService.OnlyAccessSelf(ContextUser.Email, Permission.BlogEdit))
                    {
                        if (model.CreateUser != ContextUser.Email)
                        {
                            return(Json(new { code = 502, msg = "对不起,只能编辑自己创建的记录" }));
                        }
                    }

                    model.Title       = title;
                    model.Content     = content;
                    model.HtmlContent = htmlContent;
                    model.KeyWords    = keyWords;
                    model.UrlTitle    = urlTitle;
                    model.Editor      = Convert.ToInt32(editor);
                    _articleService.Update(model);

                    try
                    {
                        _articleLabelService.RemoveByArticleId(int.Parse(articleId));
                        if (lables != null)
                        {
                            foreach (var item in lables)
                            {
                                _articleLabelService.Add(int.Parse(articleId), item);
                            }
                        }
                        RemoveHtmlFile(urlTitle);
                    }
                    catch (Exception ex)
                    {
                        LogService.Instance.AddAsync(Level.Error, ex);
                        return(Json(new { code = 503, msg = "文章保存成功,标签保存失败" }));
                    }
                }

                return(Json(new { code = 200, msg = "ok", id = articleId }));
            }
            catch (ValidateException ex)
            {
                LogService.Instance.AddAsync(Level.Error, ex);
                return(Json(new { code = ex.Code, msg = ex.Message }));
            }
            catch (Exception ex)
            {
                LogService.Instance.AddAsync(Level.Error, ex);
                return(Json(new { code = 500, msg = ex.Message }));
            }
        }