示例#1
0
        public async Task GetExistingArticleWithInformationFromDatabaseTest()
        {
            // arrange
            HAVIdatabaseContext dbContext  = CreateDbContext();
            ArticleRepository   repository = new ArticleRepository(dbContext);
            Article             article    = new Article()
            {
                Id                                  = 0,
                PurchaserId                         = 0,
                CountryId                           = 0,
                SupplierId                          = 0,
                ArticleInformationId                = 0,
                InternalArticleInformationId        = 0,
                VailedForCustomer                   = "Customer",
                DateCreated                         = DateTime.Now,
                ArticleInformationCompleted         = 0,
                InternalArticalInformationCompleted = 0,
                ArticleState                        = 0,
                ErrorReported                       = 0,
                ErrorField                          = "Field",
                ErrorMessage                        = "Message",
                ErrorOwner                          = "Owner",
                ArticleInformation                  = new ArticleInformation(),
                InternalArticleInformation          = new InternalArticleInformation()
            };
            Article addedArticle = await repository.AddArticle(article);

            // act
            Article result = await repository.GetArticleWithInformation(addedArticle.ArticleInformationId);

            // assert
            Assert.IsTrue(result == addedArticle);

            dbContext.Dispose();
        }
        public HttpResponseMessage AddArticle([FromBody] ArticleModel articleModel)
        {
            ApiResultViewModel result = new ApiResultViewModel();

            //驗證欄位資訊
            if (!ModelState.IsValid)
            {
                result.Result  = false;
                result.Status  = ResponseCode.Fail.ToString();
                result.Message = AllShared.GetModelStateError(ModelState);
                return(Request.CreateResponse(HttpStatusCode.OK, result));
            }

            //取得使用者ID
            string UserID = JWTShared.GetUserID(Request.Headers.Authorization.Parameter);

            articleModel.UID = UserID;

            bool IsSuccess = articleRepository.AddArticle(articleModel);

            if (IsSuccess)
            {
                result.Result  = true;
                result.Status  = ResponseCode.Success.ToString();
                result.Message = "新增成功!!!";
            }
            else
            {
                result.Result  = false;
                result.Status  = ResponseCode.Fail.ToString();
                result.Message = "新增資料時發生錯誤!!!";
            }

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
示例#3
0
 public static void Create()
 {
     xx1 = new Article
     {
         //Id = 1,
         PublishTime = Global.BaseTime.AddDays(-1),
         Author      = RegisterFactory.xx,
         Title       = "first",
         Body        = "virtual",
         Keywords    = new List <ArticleAndKeyword>
         {
             new ArticleAndKeyword {
                 Keyword = KeywordFactory.CSharp, Article = xx1
             },
             new ArticleAndKeyword {
                 Keyword = KeywordFactory.SQL, Article = xx1
             }
         },
         Commnets      = new List <Comment>(),
         AgreeCount    = 1,
         DisagreeCount = 0,
     };
     tt1 = new Article
     {
         //Id = 2,
         PublishTime = Global.BaseTime.AddDays(0),
         Author      = RegisterFactory.tt,
         Title       = "second",
         Body        = "same",
         Keywords    = new List <ArticleAndKeyword>
         {
             new ArticleAndKeyword {
                 Keyword = KeywordFactory.JavaScript, Article = tt1
             },
             new ArticleAndKeyword {
                 Article = tt1, Keyword = KeywordFactory.ASP
             },
         },
         Commnets      = new List <Comment>(),
         AgreeCount    = 2,
         DisagreeCount = 0
     };
     articleRepository.AddArticle(xx1);
     articleRepository.AddArticle(tt1);
     //articleRepository.AddRangeEntities(new List<Article> { xx1, tt1 });
 }
示例#4
0
        public /*ArticleNewModel*/ int UIAddArticleNewModel(ArticleNewModel articleNewModel)
        {
            Article article = mapper.Map <Article>(articleNewModel);

            article.PublishTime = DateTime.Now;
            article.Author      = new User();
            article.Author      = CurrentUser;
            return(_articleRepository.AddArticle(article));
            //articleNewModel mapperNew = mapper.Map<ArticleNewModel>(article);
        }
        public ActionResult Add(Article model)
        {
            var repo = new ArticleRepository();

            var user = User.Identity;

            ViewBag.displayMenu = "Thanks";
            model.UserId        = user.GetUserId();
            repo.AddArticle(model);
            return(View());
        }
示例#6
0
        public ActionResult UploadArticle(Article article)
        {
            if (!(User.Identity.IsAuthenticated))
            {
                return(Redirect("/"));
            }
            var userRepo = new UserRepository(Properties.Settings.Default.ConnectionString);

            article.UploadedBy = userRepo.GetUserByEmail(User.Identity.Name).Id;
            var ArticleRepo = new ArticleRepository(Properties.Settings.Default.ConnectionString);

            ArticleRepo.AddArticle(article);
            return(Redirect("/"));
        }
        public ActionResult Add(ArticleInformation aInfo)
        {
            if (ModelState.IsValid)
            {
                using (var aRepository = new ArticleRepository())
                {
                    aRepository.AddArticle(aInfo);

                    return(RedirectToAction("Manage"));
                }
            }

            return(View(aInfo));
        }
        public void CanInsertArticle()
        {
            Article articleToInsert = new Article();
            var     repo            = new ArticleRepository();

            articleToInsert.ArticleId      = 5;
            articleToInsert.ArticleTitle   = "How to survive Namek.";
            articleToInsert.ArticleContent = "A guide Namekians are DYING to read.";
            articleToInsert.DateAdded      = DateTime.Today;
            articleToInsert.UserId         = "00000000-0000-0000-0000-000000000000";
            articleToInsert.Approved       = true;

            repo.AddArticle(articleToInsert);

            Assert.AreEqual(5, articleToInsert.ArticleId);
            Assert.AreEqual(DateTime.Today, articleToInsert.DateAdded);
        }
        public async Task <ActionResult <Article> > CreateArticle(Article article)
        {
            try
            {
                if (article == null)
                {
                    return(BadRequest());
                }

                var createdArticle = await _articleRepository.AddArticle(article);

                return(createdArticle);
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Error retrieving data from the database."));
            }
        }
示例#10
0
        public IHttpActionResult Add(string Title, string Body)
        {
            var repo = new ArticleRepository();

            try
            {
                var parameters = new Article()
                {
                    ArticleContent = Body,
                    ArticleTitle   = Title
                };

                repo.AddArticle(parameters);
                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
示例#11
0
        public async Task GetExistingArticlesForPurchaserFromDatabaseTest()
        {
            // arrange
            HAVIdatabaseContext dbContext           = CreateDbContext();
            PurchaserRepository purchaserRepository = new PurchaserRepository(dbContext);
            Purchaser           purchaser           = new Purchaser()
            {
                Id        = 0,
                ProfileId = 0,
                CountryId = 0,
                Profile   = new Profile()
                {
                    Id       = 0,
                    Username = "******",
                    Password = "******",
                    Usertype = 2
                }
            };
            ArticleRepository repository = new ArticleRepository(dbContext);
            Article           article1   = new Article()
            {
                Id                                  = 0,
                PurchaserId                         = 1,
                CountryId                           = 0,
                SupplierId                          = 0,
                ArticleInformationId                = 0,
                InternalArticleInformationId        = 0,
                VailedForCustomer                   = "Customer",
                DateCreated                         = DateTime.Now,
                ArticleInformationCompleted         = 0,
                InternalArticalInformationCompleted = 0,
                ArticleState                        = 0,
                ErrorReported                       = 0,
                ErrorField                          = "Field",
                ErrorMessage                        = "Message",
                ErrorOwner                          = "Owner",
                ArticleInformation                  = new ArticleInformation(),
                InternalArticleInformation          = new InternalArticleInformation()
            };
            Article article2 = new Article()
            {
                Id                                  = 0,
                PurchaserId                         = 1,
                CountryId                           = 0,
                SupplierId                          = 0,
                ArticleInformationId                = 0,
                InternalArticleInformationId        = 0,
                VailedForCustomer                   = "Customer",
                DateCreated                         = DateTime.Now,
                ArticleInformationCompleted         = 0,
                InternalArticalInformationCompleted = 0,
                ArticleState                        = 0,
                ErrorReported                       = 0,
                ErrorField                          = "Field",
                ErrorMessage                        = "Message",
                ErrorOwner                          = "Owner",
                ArticleInformation                  = new ArticleInformation(),
                InternalArticleInformation          = new InternalArticleInformation()
            };
            await purchaserRepository.AddPurchaser(purchaser);

            Article addedArticle1 = await repository.AddArticle(article1);

            Article addedArticle2 = await repository.AddArticle(article2);

            // act
            List <Article> result = (List <Article>) await repository.GetArticlesForPurchaser(1);

            // assert
            Assert.IsTrue(result.Count == 2);
            Assert.IsTrue(result.Contains(addedArticle1));
            Assert.IsTrue(result.Contains(addedArticle2));

            dbContext.Dispose();
        }
示例#12
0
 public int AddArticle(AC_Article m)
 {
     return(ar.AddArticle(m));
 }