Ejemplo n.º 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            article article = _articleService.FindById(id);

            _articleService.Delete(article);
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public void ArticleDelete()
        {
            articleService.Delete("1d8e186d-0d30-4f1a-91d5-cd9294d7015f");
            Article article = articleService.GetArticleById("1d8e186d-0d30-4f1a-91d5-cd9294d7015f");

            Assert.IsNull(article);
        }
Ejemplo n.º 3
0
        public async Task DeleteShouldDeleteArticleById()
        {
            var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var dbContext = new ApplicationDbContext(optionsBuilder.Options);

            var articleService = new ArticleService(dbContext, null);

            var article = new Article
            {
                Content   = "testContent",
                ImageUrl  = "testImageUrl",
                Title     = "testTitle",
                Id        = 4,
                UserId    = "Icaka99",
                CreatedOn = DateTime.Now,
                User      = new ApplicationUser
                {
                    UserName = "******",
                },
            };

            await dbContext.Articles.AddAsync(article);

            await dbContext.SaveChangesAsync();

            articleService.Delete(4);

            Assert.False(dbContext.Articles.Any());
        }
Ejemplo n.º 4
0
        public void ShouldDeleleteTags_WhenDeleteArticle()
        {
            // assign
            var article = new Article
            {
                Id          = 1,
                ArticleTags = new HashSet <ArticleTags>
                {
                    new ArticleTags {
                        ArticleId = 1, TagId = 1
                    }
                }
            };
            var articleRepositoryMock = new Mock <IArticleRepository>();

            articleRepositoryMock.Setup(t => t.Find(article.Id)).Returns(article);
            var articleTagRelationMock = new Mock <IArticlesTagsRelationRepository>();

            var articleRepository           = articleRepositoryMock.Object;
            var articleTagRelationRepositry = articleTagRelationMock.Object;

            ArticleService articleService = new ArticleService(articleRepository, null, articleTagRelationRepositry);

            // act
            articleService.Delete(article.Id);

            // assert
            articleTagRelationMock.Verify(t => t.Delete(article.ArticleTags.First()));
        }
Ejemplo n.º 5
0
        static void Transaction()
        {
            var customer = new Customer {
                Name = "好久不见"
            };

            try
            {
                // 测试事务
                dbContext.BeginTransaction();
                dbContext.Customer.Insert.Add(customer);
                List <Customer> li = new List <Customer>
                {
                    new Customer {
                        Name = "test"
                    }
                };
                dbContext.Customer.Insert.AddRange(li).SaveChange();
                dbContext.Customer.Update.SetValue(a => a.Name, "12345").Where(f => f.Id == customer.Id).SaveChange();
                dbContext.CommitTransaction();

                ArticleService articleService = new ArticleService(dbContext);
                var            art            = articleService.Detail(13);
                if (art != null)
                {
                    art = articleService.Update(art.Id, "修改了标题", art.Content);
                    bool success = articleService.Delete(art.Id);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
        public IActionResult DeleteArticle(long articleID)
        {
            var user = UserService.Get(long.Parse(User.Identity.Name));

            if (user == null)
            {
                return(NotFound(new ResponseModel
                {
                    Success = false,
                    Message = "Пользователь не найден"
                }));
            }

            if (user.Role == UserRole.Client)
            {
                return(BadRequest(new ResponseModel
                {
                    Success = false,
                    Message = "Ошибка доступа"
                }));
            }

            var specialist = SpecialistService.GetSpecialistFromUser(user);

            if (specialist == null)
            {
                return(BadRequest(new ResponseModel
                {
                    Success = false,
                    Message = "Ошибка доступа"
                }));
            }

            var article = ArticleService.Get(articleID);

            if (article == null)
            {
                return(NotFound(new ResponseModel
                {
                    Success = false,
                    Message = "Статья не найдена"
                }));
            }

            if (article.Author != specialist)
            {
                return(BadRequest(new ResponseModel
                {
                    Success = false,
                    Message = "Ошибка доступа"
                }));
            }

            var articlePublish = ArticlePublishService.GetArticlePublish(article);

            ArticleService.Delete(article);
            ArticlePublishService.Delete(articlePublish);

            return(Ok(new ResponseModel()));
        }
Ejemplo n.º 7
0
        public HttpResponseMessage Delete(string id)
        {
            var svc = new ArticleService();

            svc.Delete(id);
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Ejemplo n.º 8
0
        public void TestDelete()
        {
            mockArticleRepository.Setup(x => x.Delete(It.IsAny <string>())).Returns(true);
            var  _articleService = new ArticleService(mockArticleRepository.Object);
            bool checkdeleted    = _articleService.Delete("abc");

            Assert.IsTrue(checkdeleted);
        }
Ejemplo n.º 9
0
        public IActionResult Delete(int id)
        {
            string userId = _userManager.GetUserId(User);

            _articleService.Delete(id, userId);

            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 10
0
 public ActionResult Delete(string id)
 {
     if (id == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     articleCRUD.Delete(id);
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 11
0
 public ActionResult DeleteArticles(int?id)
 {
     if (id != null)
     {
         Article art = artdb.GetById((int)id);
         artdb.Delete(art);
     }
     return(RedirectToAction("Articles", "Admin", "Admin"));
 }
Ejemplo n.º 12
0
        public ActionResult Delete(Guid id)
        {
            var itemForDelete = ArticleService.Get(id);

            ArticleService.Delete(itemForDelete.Id);
            ArticleService.Save();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 13
0
        public ActionResult Delete(string id, int currentPage = 1, int pageSize = 10)
        {
            var article = new ArticleService();

            article.Delete(id);
            ViewBag.CategoryList = new CategoryService().GetList();
            var data = article.GetPageList(null, currentPage, pageSize);

            return(View("Index", data));
        }
Ejemplo n.º 14
0
        public async Task DeleteShouldThrowExceptionsSuccessfully(int articleId)
        {
            this.SetupSqlite();
            await this.SeedDatabase();

            using var context = new ApplicationDbContext(this.ContextOptions);

            var repository     = new EfDeletableEntityRepository <Article>(context);
            var articleService = new ArticleService(repository);

            await Assert.ThrowsAsync <ArgumentNullException>(() => articleService.Delete(articleId));
        }
        public async Task ArticlesDeletionWorkingProperly()
        {
            //Assert
            var articleService = new ArticleService(this.db);

            //Act
            articleService.Delete(2);
            var result = articleService.Get(2);

            //Assert
            Assert.That(result == null);
        }
Ejemplo n.º 16
0
 private void DeleteRootArticle(int productId, bool checkRootArticlePermissions)
 {
     if (checkRootArticlePermissions)
     {
         var result = ArticleService.Delete(productId);
         ValidateMessageResult(productId, result);
     }
     else
     {
         ArticleService.SimpleDelete(new[] { productId });
     }
 }
Ejemplo n.º 17
0
        public ActionResult Delete(int?id)
        {
            try
            {
                db.Delete(id);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 18
0
        public async Task Delete_DeleteArticle()
        {
            //Arrange
            var dummyId = "anyid";

            _mockArticleRepository.Setup(repo => repo.Delete(dummyId)).Returns(Task.CompletedTask);

            //Act
            await _articleService.Delete(dummyId);

            //Assert
            Assert.Pass();
        }
Ejemplo n.º 19
0
        public async Task DeleteShouldExecuteSuccessfully(int articleId)
        {
            this.SetupSqlite();
            await this.SeedDatabase();

            using var context = new ApplicationDbContext(this.ContextOptions);

            var repository     = new EfDeletableEntityRepository <Article>(context);
            var articleService = new ArticleService(repository);

            var deleteResult = await articleService.Delete(articleId);

            Assert.True(deleteResult);
        }
Ejemplo n.º 20
0
        private static void Clear()
        {
            var contentService          = new ContentApiService(Global.ConnectionString, 1);
            var baseContentExists       = contentService.Exists(BaseContentId);
            var dictionaryContentExists = contentService.Exists(DictionaryContentId);
            var fieldService            = new FieldApiService(Global.ConnectionString, 1);

            if (dictionaryContentExists)
            {
                InitDictionaryContentFields();
                var dictionaryIds = Global.GetIds(DbConnector, DictionaryContentId);
                ArticleService.Delete(DictionaryContentId, dictionaryIds);
            }

            if (baseContentExists)
            {
                InitBaseContentFields();
                InitExtensions();

                var baseIds = Global.GetIds(DbConnector, BaseContentId);
                ArticleService.Delete(BaseContentId, baseIds);
                contentService.Delete(Ex11ContentId);
                contentService.Delete(Ex12ContentId);
                contentService.Delete(Ex21ContentId);
                contentService.Delete(Ex22ContentId);
            }

            if (dictionaryContentExists)
            {
                fieldService.Delete(DictionaryFieldMtMBackwardId);
                fieldService.Delete(DictionaryFieldMtOBackwardId);
            }

            if (baseContentExists)
            {
                fieldService.Delete(BaseFieldMtMId);
                fieldService.Delete(BaseFieldOtMId);
            }

            if (dictionaryContentExists)
            {
                contentService.Delete(DictionaryContentId);
            }

            if (baseContentExists)
            {
                contentService.Delete(BaseContentId);
            }
        }
Ejemplo n.º 21
0
        public void BatchUpdate_DictionaryContent_RecoverContentData()
        {
            var random = Guid.NewGuid().ToString();
            var key    = "key_" + random;
            var value  = "value_" + random;
            var data   = new[]
            {
                new ArticleData
                {
                    ContentId = DictionaryContentId,
                    Id        = -1,
                    Fields    = new[]
                    {
                        new FieldData
                        {
                            Id    = DictionaryKeyId,
                            Value = string.Empty
                        },
                        new FieldData
                        {
                            Id    = DictionaryValueId,
                            Value = string.Empty
                        },
                        new FieldData
                        {
                            Id = DictionaryFieldMtMBackwardId
                        },
                        new FieldData
                        {
                            Id = DictionaryFieldMtOBackwardId
                        }
                    }.ToList()
                }
            };

            var result = ArticleService.BatchUpdate(data);

            Assert.That(result, Is.Not.Null, BatchUpdateResultIncorrect);
            Assert.That(result, Has.Length.EqualTo(1));

            var articleResult = result[0];

            Assert.That(articleResult.ContentId, Is.EqualTo(DictionaryContentId));
            Assert.That(articleResult.CreatedArticleId, Is.Not.EqualTo(articleResult.OriginalArticleId));

            data[0].Id = articleResult.CreatedArticleId;
            data[0].Fields[0].Value = key;
            data[0].Fields[1].Value = value;

            Global.ClearContentData(DbConnector, articleResult.CreatedArticleId);
            result = ArticleService.BatchUpdate(data);
            Assert.That(result, Is.Not.Null.And.Empty, BatchUpdateResultIncorrect);

            var contentData = Global.GetContentData(DbConnector, articleResult.CreatedArticleId);

            Assert.That(contentData, Is.Not.Null);
            Assert.That(contentData, Has.Length.EqualTo(4), ContentDataIsEmpty);

            using (new QPConnectionScope(Global.ConnectionString))
            {
                var article = ArticleService.Read(articleResult.CreatedArticleId);
                Assert.That(article, Is.Not.Null, CantReadArticle);

                var keyFv = article.FieldValues.Single(fv => fv.Field.Name == DictionaryKey);
                Assert.That(keyFv, Is.Not.Null);
                Assert.That(key, Is.EqualTo(keyFv.Value));
                Assert.That(contentData.Any(itm => itm.FieldId == DictionaryKeyId && itm.Data == key));

                var valueFv = article.FieldValues.Single(fv => fv.Field.Name == DictionaryValue);
                Assert.That(valueFv, Is.Not.Null);
                Assert.That(value, Is.EqualTo(valueFv.Value));
                Assert.That(contentData.Any(itm => itm.FieldId == DictionaryValueId && itm.Data == value));

                var mtoValue = GetFieldValue <decimal?>(DictionaryContentId, DictionaryFieldMtOBackward, articleResult.CreatedArticleId);
                Assert.That(mtoValue, Is.EqualTo(BaseFieldOtMId), WrongMtORelation);
                Assert.That(contentData.Any(itm => itm.FieldId == DictionaryFieldMtOBackwardId && itm.Data == BaseFieldOtMId.ToString(CultureInfo.InvariantCulture)), WrongMtORelation);

                var mtmValue = GetFieldValue <decimal?>(DictionaryContentId, DictionaryFieldMtMBackward, articleResult.CreatedArticleId);
                Assert.That(mtmValue, Is.Not.Null, WrongMtMRelation);

                var mtmFv = article.FieldValues.Single(fv => fv.Field.Name == DictionaryFieldMtMBackward);
                Assert.That(mtmFv, Is.Not.Null);
                Assert.That(mtmFv.Field.Default, Is.EqualTo(mtmValue.Value.ToString(CultureInfo.InvariantCulture)), WrongMtMRelation);
                Assert.That(contentData.Any(itm => itm.FieldId == DictionaryFieldMtMBackwardId && itm.Data == mtmFv.Field.Default), WrongMtMRelation);

                ArticleService.Delete(article.Id);
            }
        }
Ejemplo n.º 22
0
 public ActionResult DeleteConfimed(int id)
 {
     service.Delete(id);
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 23
0
        public void ArticleDelete()
        {
            ArticleService articleCRUD = new ArticleService();

            articleCRUD.Delete("8a2c21bf-06f9-4e18-8d7f-15299a28c53c");
        }
Ejemplo n.º 24
0
 public void Delete(Article entity)
 => articleService.Delete(entity);
Ejemplo n.º 25
0
        public IActionResult Delete(int id)
        {
            articleService.Delete(id);

            return(Ok(id));
        }
Ejemplo n.º 26
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex < 0 || e.RowIndex > (articles.Count - 1) || e.RowIndex < 0)
            {
                return;
            }

            var senderGrid = (DataGridView)sender;
            var column     = senderGrid.Columns[e.ColumnIndex];

            if (column.Tag == null)
            {
                return;
            }

            if (column.Tag.ToString() != ADD_QUANT_COLUMN_NAME &&
                column.Tag.ToString() != SUB_QUANT_COLUMN_NAME &&
                column.Tag.ToString() != UPDATE_PRICE_NAME &&
                column.Tag.ToString() != DELETE_NAME
                )
            {
                return;
            }

            if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
                e.RowIndex >= 0)
            {
                String input = "";
                int    quant = 0;

                try
                {
                    var article = articles[e.RowIndex];

                    if (column.Tag.ToString() == ADD_QUANT_COLUMN_NAME)
                    {
                        input = ChangeQuantPrompt.ShowDialog("Menge: ", "Menge hinzufügen fur " + article.GetArtNo());
                        if (String.IsNullOrEmpty(input))
                        {
                            return;
                        }
                        quant = Int32.Parse(input);
                        ArticleService.AddQuant(article, quant);
                    }
                    else if (column.Tag.ToString() == SUB_QUANT_COLUMN_NAME)
                    {
                        input = ChangeQuantPrompt.ShowDialog("Menge: ", "Menge subtrahieren fur " + article.GetArtNo());
                        if (String.IsNullOrEmpty(input))
                        {
                            return;
                        }
                        quant = Int32.Parse(input);
                        ArticleService.SubQuant(article, quant);
                    }
                    else if (column.Tag.ToString() == UPDATE_PRICE_NAME)
                    {
                        input = ChangePricePrompt.ShowDialog("Preis :", "Preis ändern fur " + article.GetArtNo());
                        if (String.IsNullOrEmpty(input))
                        {
                            return;
                        }
                        var price = Decimal.Parse(input, Thread.CurrentThread.CurrentCulture.NumberFormat);
                        ArticleService.UpdatePrice(article, price);
                    }
                    else if (column.Tag.ToString() == DELETE_NAME)
                    {
                        var result = ConfirmationPrompt.ShowDialog("Möchten Sie es wirklich löschen?", "Löschen", "Ja", "Nein");
                        if (result)
                        {
                            ArticleService.Delete(article);
                        }
                    }

                    LoadArticles();
                }
                catch (ArgumentException ex)
                {
                    MessageBox.Show("Ungültige Eingabe");
                }
                catch (FormatException ex)
                {
                    MessageBox.Show("Ungültige Eingabe");
                }
                catch (Exception ex1)
                {
                    MessageBox.Show(ex1.Message);
                }
            }
        }
Ejemplo n.º 27
0
 public MessageResult Delete(int articleId)
 {
     return(ArticleService.Delete(articleId));
 }
Ejemplo n.º 28
0
 [Authorize(Roles = "Admin")] //設定此Action只有Admin角色才可使用
 public ActionResult Delete(int Id)
 {
     articleService.Delete(Id);         //使用Service來刪除資料
     return(RedirectToAction("Index")); //重新導向頁面至開始頁面
 }
Ejemplo n.º 29
0
        public ActionResult DeleteArticle(string id)
        {
            var deleteResult = _articleService.Delete(new ObjectId(id));

            return(NoContent());
        }
Ejemplo n.º 30
0
        public void BatchUpdate_DictionaryContent_InsertArticle()
        {
            var random = Guid.NewGuid().ToString();
            var key    = "key_" + random;
            var value  = "value_" + random;
            var data   = new[]
            {
                new ArticleData
                {
                    ContentId = DictionaryContentId,
                    Id        = -1,
                    Fields    = new[]
                    {
                        new FieldData
                        {
                            Id    = DictionaryKeyId,
                            Value = key
                        },
                        new FieldData
                        {
                            Id    = DictionaryValueId,
                            Value = value
                        },
                        new FieldData
                        {
                            Id = DictionaryFieldMtMBackwardId
                        },
                        new FieldData
                        {
                            Id = DictionaryFieldMtOBackwardId
                        }
                    }.ToList()
                }
            };

            var result = ArticleService.BatchUpdate(data);

            Assert.That(result, Is.Not.Null, BatchUpdateResultIncorrect);
            Assert.That(result, Has.Length.EqualTo(1));
            var articleResult = result[0];

            Assert.That(DictionaryContentId, Is.EqualTo(articleResult.ContentId));
            Assert.That(articleResult.OriginalArticleId, Is.Not.EqualTo(articleResult.CreatedArticleId));

            using (new QPConnectionScope(Global.ConnectionString))
            {
                var article = ArticleService.Read(articleResult.CreatedArticleId);
                Assert.That(article, Is.Not.Null, CantReadArticle);

                var keyFv = article.FieldValues.Single(fv => fv.Field.Name == DictionaryKey);
                Assert.That(keyFv, Is.Not.Null);
                Assert.That(key, Is.EqualTo(keyFv.Value));

                var valueFv = article.FieldValues.Single(fv => fv.Field.Name == DictionaryValue);
                Assert.That(valueFv, Is.Not.Null);
                Assert.That(value, Is.EqualTo(valueFv.Value));

                var mtoValue = GetFieldValue <decimal?>(DictionaryContentId, DictionaryFieldMtOBackward, articleResult.CreatedArticleId);
                Assert.That(mtoValue, Is.EqualTo(BaseFieldOtMId), WrongMtORelation);

                var mtmValue = GetFieldValue <decimal?>(DictionaryContentId, DictionaryFieldMtMBackward, articleResult.CreatedArticleId);
                Assert.That(mtmValue, Is.Not.Null, WrongMtMRelation);
                var mtmFv = article.FieldValues.Single(fv => fv.Field.Name == DictionaryFieldMtMBackward);
                Assert.That(mtmFv, Is.Not.Null);
                Assert.That(mtmFv.Field.Default, Is.EqualTo(mtmValue.Value.ToString(CultureInfo.InvariantCulture)), WrongMtMRelation);

                ArticleService.Delete(article.Id);
            }
        }