public void AddToMsSql(Article article)
        {
            Article art = GetArticle();

            _articleRepository.Add(art);
            _msSqlUnitOfWork.SaveChanges();
        }
Пример #2
0
 public async Task <bool> AddEntityAsync(Article t)
 {
     return(await Task.Run(() =>
     {
         t.ArticleCreateTime = DateTime.Now;
         t.ArticleLikes = 0;
         t.ArticleVisits = 0;
         t.IsShow = 1;
         return _repository.Add(t);
     }));
 }
        public async Task <ArticleDTO> AddArticle(ArticleDTO dto)
        {
            var article = Mapper.Map <ArticleDTO, Article>(dto);
            await _articleRepository.Add(article);

            return(dto);
        }
Пример #4
0
        public ActionResult Create([Bind("Id,Title,Content,IsDraft,PublishStartDate,PublishEndDate,SefName,Category,Tags")] CreateArticleViewModel model)
        {
            try
            {
                //ModelState.Remove("Category.Name");
                //ModelState.Remove("Category.SefName");
                if (ModelState.IsValid)
                {
                    string currentUser = _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);
                    var    article     = _articleFactory.CreateArticleFromViewModel_Create(model, currentUser);

                    var id = _articleRepository.Add(article, model.Tags, currentUser);
                    if (article.IsDraft == 0)
                    {
                        //KbVaultLuceneHelper.AddArticleToIndex(article);
                        _lucene.AddArticleToIndex(article);
                    }

                    //vrati se
                    //ShowOperationMessage(UIResources.ArticleCreatePageCreateSuccessMessage);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                ModelState.AddModelError("Exception", ex.Message);
            }

            return(RedirectToAction(nameof(Index)));
        }
Пример #5
0
        public ActionResult Action(tblArticle objSubmit)
        {
            if (objSubmit.ID == 0)
            {
                objSubmit.DateCreated = DateTime.Now;
                objSubmit.DateUpdated = DateTime.Now;
                objSubmit.IsDeleted   = false;
                objSubmit.IsShow      = true;
                articleRepository.Add(objSubmit);
            }
            else
            {
                var obj = articleRepository.GetById <tblArticle>(objSubmit.ID);

                UpdateModel(obj);

                objSubmit.DateUpdated = DateTime.Now;

                articleRepository.Update(obj);
            }

            articleGroupMapRepository.ResetGroupOfNews(objSubmit.ID, Web365Utility.Web365Utility.StringToArrayInt(Request["groupID"]));

            return(Json(new
            {
                Error = false
            }, JsonRequestBehavior.AllowGet));
        }
 public int AddArticle(Model.Article article)
 {
     if (_roleService.AddArticlePower())
     {
         if (string.IsNullOrEmpty(article.Title))
         {
             throw new DomainException("Title", "文章标题不能为空!");
         }
         else if (string.IsNullOrEmpty(article.Content))
         {
             throw new DomainException("Content", "文章内容不能为空!");
         }
         else if (article.Categorys.Count == 0)
         {
             throw new DomainException("Category", "文章必须要有一个分类!");
         }
         article.Status = ArticleStatus.Open;
         article.Author = _userService.GetLoginUser();
         IList <Category> categorys = article.Categorys;
         article.Categorys = null;
         int id = _articleRepository.Add(article);
         article.Categorys = categorys;
         _articleRepository.Update(article);
         return(id);
     }
     else
     {
         throw new DomainException("NoPower", "对不起,您没有权限添加文章。");
     }
 }
Пример #7
0
        public Article Create(Article article, string emailVendor)
        {
            var user = _userRepository.GetOne(emailVendor);

            article.Vendor = user;
            return(_articleRepository.Add(article));
        }
Пример #8
0
        public ActionResult Create(ArticleViewModel model)
        {
            if (ModelState.IsValid)
            {
                var entry = new Article
                {
                    Title      = model.Title,
                    Content    = model.Content,
                    Pin        = model.Pin,
                    Status     = model.Status,
                    CategoryID = model.CategoryID,
                    Thumbnail  = model.Thumbnail,

                    CreateAt = DateTime.Now,
                    View     = 0
                };

                //Tag
                AddOrUpdateTags(entry, model.Tags);

                articleRepository.Add(entry);
                return(RedirectToIndex());
            }

            return(View(model));
        }
Пример #9
0
        public async Task <Article> Create(ArticleInputModel newArticle, UserInfo userInfo)
        {
            if (userInfo == null)
            {
                throw new NotAuthException();
            }

            var article = ArticleFromInputModelNew(newArticle);

            article.UserId = userInfo.UserId;
            try
            {
                article.MainImagePath = await _imageService.CreateUploadFileWithOutDbRecord(newArticle.MainImageNew);

                article = await _articleRepository.Add(article);


                article.AdditionalImages = await _imageService.Upload(newArticle.AdditionalImages, article.Id);

                return(article);
            }
            catch
            {
                if (article.AdditionalImages?.Count > 0)
                {
                    //TODO картинки надо попытаться удалить
                    await _imageService.DeleteFull(article.AdditionalImages);
                }
                throw;
            }
        }
Пример #10
0
        public async Task <OperationResult> Create(Article_Dto model)
        {
            var item = await GetArticleByID(model.Article_Cate_ID, model.Article_ID);

            var data = _mapper.Map <Article>(model);

            try
            {
                if (item == null)
                {
                    _articleRepository.Add(data);
                    await _articleRepository.Save();

                    operationResult = new OperationResult {
                        Success = true, Message = "Article was successfully added."
                    };
                }
                else
                {
                    operationResult = new OperationResult {
                        Success = true, Message = "Article was exists."
                    };
                }
            }
            catch (System.Exception ex)
            {
                operationResult = new OperationResult {
                    Success = true, Message = ex.ToString()
                };
            }

            return(operationResult);
        }
Пример #11
0
 public void Add(Article article, int?userid)
 {
     article.UserId        = userid.Value;
     article.PublishedDate = System.DateTime.Now;
     _articleRepository.Add(article);
     _articleRepository.Save();
 }
Пример #12
0
        public ArticleDetailModel AddArticle(ArticleCreateModel articleModel)
        {
            var article = new Article(articleModel.Author, articleModel.Heading, articleModel.Content);

            _articleRepository.Add(article);
            return(ToPublicModel(article));
        }
Пример #13
0
        public Article CreateArticle(Article entity)
        {
            var returned = _articleRepository.Add(entity);

            _articleRepository.SaveChanges();

            return(returned);
        }
Пример #14
0
        public void AddOneArticleTest()
        {
            article1 = inMemoryArticleRepository.Add(article1);
            List <Article> articleList = inMemoryArticleRepository.GetAll();

            Assert.AreEqual(articleList.Count, 1);
            Assert.AreEqual(article1.Id, 1);
            Assert.AreNotEqual(article1.CreatedAt, new DateTime());
            Assert.AreNotEqual(article1.LastModified, new DateTime());
        }
Пример #15
0
        public void When透過Add方法新增一筆資料到Article裡面()
        {
            var article = ScenarioContext.Current.Get <Article>("Article");

            _ArticleRepository.Add(article);
            var act = _CmsEntitiesTest.Articles.AsNoTracking();

            ScenarioContext.Current.Set(act, "act");
        }
 public IActionResult New(Article article)
 {
     if (ModelState.IsValid)
     {
         _articleRepository.Add(article);
         return(RedirectToAction("AdminHome", "Home"));
     }
     return(View(article));
 }
Пример #17
0
        public async Task <Entities.Storage.Article> Add(ArticleRequest request)
        {
            if (request.Article.Author.Role == Role.Default && request.Article.Type == ArticleType.Shared)
            {
                return(null);
            }

            return(await _articleRepository.Add(request));
        }
Пример #18
0
 public IActionResult Add(Article a)
 {
     TryValidateModel(a);
     if (ModelState.IsValid)
     {
         db.Add(a);
         return(RedirectToAction("List"));
     }
     return(View(a));
 }
Пример #19
0
        public void When使用Add方法新增()
        {
            mork.Add(Arg.Any <Article>()).Returns(true);
            var articleInfo = ScenarioContext.Current.Get <ArticleInfo>("articleInfo");

            //act
            bool act = _articleService.Add(articleInfo);

            ScenarioContext.Current.Set(act, "act");
        }
Пример #20
0
        // POST api/values
        public async Task Post(ArticleModel am)
        {
            Article article = await _repo.FindByUrlAsync(am.Url);

            if (article == null)
            {
                article = new Article(Guid.NewGuid(), am.Url);
                _repo.Add(article);
                await this._unitOfWork.SaveChangesAsync();
            }
        }
Пример #21
0
        public async Task <Article> Add(Article article, string photoURL)
        {
            if (_articleRepository.SearchAsync(a => a.Content == article.Content).Result.Any())
            {
                return(null);
            }

            await _articleRepository.Add(article, photoURL);

            return(article);
        }
Пример #22
0
        public void CreateArticle(Article article)
        {
            var id = _articleRepository.FindIdByTitle(article.Title);

            if (id != null)
            {
                throw new ArticleDomainEntityExistsException($"文章 {article.Title} 已经存在");
            }
            _articleRepository.Add(article);
            _domainEventPublisher.PublishEvent(new NewArticleCreateDomainEvent(article));
        }
Пример #23
0
        public int AddArticle(Article article)
        {
            _articleRepository.Add(article);

            string sql  = @"insert into ArticleContents(ArticleId, Content) values (@ArticleId, @Content)";
            var    conn = GetOpenConnection();

            conn.Execute(sql, new { ArticleId = article.Id, Content = article.Content });
            conn.Close();
            return(article.Id);
        }
Пример #24
0
 public void AddArticle(string email, string title, string content, DateTime date)
 {
     //verificare daca exista email-ul
     _articleRepository.Add(new Article()
     {
         //De adaugat tag-uri
         AuthorId = _authorRepository.GetAuthorIdBy(email),
         Content  = content,
         Title    = title,
         Date     = date
     });
 }
Пример #25
0
        public IArticle Add(Article entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            entity.Tags = tagService.GetByName(entity.Tags.Select(x => x.Name)).ToList();

            var addedArticle = articleRepository.Add(entity);

            return(addedArticle);
        }
Пример #26
0
 public ActionResult Create(ArticleViewModel model)
 {
     ModelState.Remove("Id");
     if (ModelState.IsValid)
     {
         model.UserId = User.Identity.GetUserId();
         var article = new Article(model);
         _articleRepository.Add(article);
         _articleRepository.Save();
         return(RedirectToAction("Index"));
     }
     return(View("Create", model));
 }
Пример #27
0
 public void CreateArticle(Article article)
 {
     try
     {
         _articleRepository.Add(article);
         _unitOfWork.Commit();
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
Пример #28
0
        public IActionResult Add([FromBody] ArticleModel article)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            article.Created = DateTime.Now;
            article.Status  = Enums.Status.Active;

            articleRepository.Add(article);

            return(new OkObjectResult(article));
        }
Пример #29
0
        public void CreateArticle(Article article)
        {
            lock (CreateLock)
            {
                var id = _articleRepository.FindIdByTitle(article.Title);
                if (!string.IsNullOrEmpty(id))
                {
                    throw new ArticleDomainEntityExistsException($"文章 {article.Title} 已经存在");
                }
                _articleRepository.Add(article);
            }

            _domainEventPublisher.PublishEvent(new NewArticleCreateDomainEvent(article));
        }
Пример #30
0
        public async Task <IActionResult> Add([FromBody] ArticleDto data)
        {
            if (ModelState.IsValid)
            {
                var SaveData = _mapper.Map <Articles>(data);

                _ArticleRepository.Add(SaveData);
                await _ArticleRepository.SaveAll();


                return(Ok(SaveData));
            }
            return(BadRequest("Kayıt Yapılamadı "));
        }