public IActionResult Create([Bind("Title,Content,Image,ArticleTopics")] Article article) { if (ModelState.IsValid) { int memberID = int.Parse(HttpContext.Request.Cookies["ID"]); article.MemberID = memberID; _articleRepository.Add(article); return(RedirectToAction(nameof(List))); } ViewBag.Topics = new MultiSelectList(_topicRepository.GetAll(), "ID", "Name"); return(View(article)); }
public ActionResult Create([Bind(Exclude = "Category.Name")] ArticleViewModel model) { try { ModelState.Remove("Category.Name"); if (ModelState.IsValid) { var article = ArticleFactory.CreateArticleFromViewModel(model, KBVaultHelperFunctions.UserAsKbUser(User).Id); var id = ArticleRepository.Add(article, model.Tags); if (article.IsDraft == 0) { KbVaultLuceneHelper.AddArticleToIndex(article); } ShowOperationMessage(UIResources.ArticleCreatePageCreateSuccessMessage); return(RedirectToAction("Edit", "Article", new { id = article.Id })); } return(View(model)); } catch (Exception ex) { Log.Error(ex); ModelState.AddModelError("Exception", ex.Message); return(View(model)); } }
protected async Task Parse(IEnumerable <Article> articles) { var counter = 0; var count = articles.Count(); articles = _articleRepository.FilterParsedArticles(articles, _site); foreach (var article in articles) { try { var art = await Parse(article); _articleRepository.Add(art, _site.Id); await _articleRepository.Save(); } catch { } Console.WriteLine($"{counter++} av {count}"); } //var tasks = _articleRepository.FilterParsedArticles(articles).Select(Parse).ToArray(); //return await Task.WhenAll(tasks); }
// TODO: Maybe this get methods can convert to pagination structure. public bool AddArticle(ArticleInsertModel articleInsertModel) { Article article = mapper.Map <ArticleInsertModel, Article>(articleInsertModel); articleRepository.Add(article); return(true); }
private static void Main() { var c = new Category(); c.Name = "Some category"; var categoryRepository = new CategoryRepository(); categoryRepository.Add(c); var a = new Article(); a.Category = c; a.Content = "Some content"; a.Title = "Some title"; var repository = new ArticleRepository(); // give the static checker a helping hand // we don't want to proceed if a is not valid anyway if (!a.IsValid) { throw new InvalidOperationException("Hard to check statically"); // alternatively, do "Contract.Assume(a.IsValid)" } repository.Add(a); Console.WriteLine("Done"); }
public void Add_Returns_1_When_Adding_Valid_Order() { var databaseName = Guid.NewGuid().ToString(); using (var context = DbContextFactory.CreateInstance(databaseName)) { //Arrange var productRepository = new ProductRepository(context); var articleRepository = new ArticleRepository(context); var customerRepository = new CustomerRepository(context); var orderRepository = new OrderRepository(context); var orderLineRepository = new OrderLineRepository(context); //Act var product = ProductFactory.CreateValidEntity(); productRepository.Add(product); var article = ArticleFactory.CreateValidEntity(product); articleRepository.Add(article); var customer = CustomerFactory.CreateValidEntity(); customerRepository.Add(customer); var order = OrderFactory.CreateValidEntity(customer); orderRepository.Add(order); var orderLine = OrderLineFactory.CreateValidEntity(order, article); orderLineRepository.Add(orderLine); var result = context.SaveChanges(); //Assert Assert.AreEqual(5, result); //Because we added five entities } }
public ActionResult Write(Article article) { var a = TryValidateModel(article); NLog.LogManager.GetCurrentClassLogger().Debug("是否通过====" + a); if (ModelState.IsValid) { article.PubDate = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); var flag = repository.Add(article); HandlerResult result = null; if (flag) { result = new HandlerResult { IsSuccess = true, Message = "操作成功" }; } else { result = new HandlerResult { IsSuccess = false, Message = "操作失败" }; } return(View("Index")); } return(View(article)); }
public ActionResult AddArticle([Bind(Prefix = "Item1")] Article item, HttpPostedFileBase resim) { item.CreatedBy = (Session["admin"] as AppUser).UserName; item.ImagePath = ImageUploader.UploadImage("~/Pictures", resim); article_repo.Add(item); return(RedirectToAction("ListArticle")); }
public void GetAll_Returns_10_Products() { var databaseName = Guid.NewGuid().ToString(); using (var context = DbContextFactory.CreateInstance(databaseName)) { //Arrange var productRepository = new ProductRepository(context); var articleRepository = new ArticleRepository(context); for (int i = 0; i < 10; i++) { var product = ProductFactory.CreateValidEntity(); productRepository.Add(product); var articleToAdd = ArticleFactory.CreateValidEntity(product); articleRepository.Add(articleToAdd); } context.SaveChanges(); //Act var articles = articleRepository.GetAll(); //Assert Assert.AreEqual(10, articles.Count()); } }
public void Get_Returns_Order_When_Found() { var databaseName = Guid.NewGuid().ToString(); using (var context = DbContextFactory.CreateInstance(databaseName)) { //Arrange var productRepository = new ProductRepository(context); var articleRepository = new ArticleRepository(context); var customerRepository = new CustomerRepository(context); var orderRepository = new OrderRepository(context); var orderLineRepository = new OrderLineRepository(context); var product = ProductFactory.CreateValidEntity(); productRepository.Add(product); var article = ArticleFactory.CreateValidEntity(product); articleRepository.Add(article); var customer = CustomerFactory.CreateValidEntity(); customerRepository.Add(customer); var order = OrderFactory.CreateValidEntity(customer); orderRepository.Add(order); var orderLineToAdd = OrderLineFactory.CreateValidEntity(order, article); orderLineRepository.Add(orderLineToAdd); context.SaveChanges(); //Act var orderLine = orderLineRepository.Get(orderLineToAdd.Id); //Assert Assert.IsNotNull(orderLine); } }
public void Add(ArticleDTO article) { string user = Membership.GetUser().UserName; article.CreatedBy = user; repo.Add(article); }
public Article Restore() { var article = CreateAggregateRoot(); var repos = new ArticleRepository(); repos.Add(article); article = repos.Restore(article.Id, out int version); Assert.NotNull(article); return(article); }
public IActionResult Create(Article article) { if (ModelState.IsValid) { _articleRepository.Add(article); _db.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(View(article)); }
static void Main(string[] args) { //test ArticleRepository articles = new ArticleRepository(); Article article = new Article { Id = 4, Category = "Ekonomi", Title = "Barcelona yenildi", Body = "Test Body" }; articles.Add(article); }
public ActionResult Create(Article article) { if (!ModelState.IsValid) { return(View(article)); } repository.Add(article); repository.SaveChanges(); return(RedirectToAction("Index")); }
public void Update() { var article = CreateAggregateRoot(); var repos = new ArticleRepository(); repos.Add(article); article = repos.Restore(article.Id, out int version); article.Publish(); Assert.True(repos.Update(article, version)); Assert.False(repos.Update(article, version)); }
public void CanGetAllArticlesFromPostgre() { var articleRepository = new ArticleRepository(dbConnectionString); var articleText = "Test Text"; var articleTitle = Guid.NewGuid().ToString(); var articleAuthor = "Bob"; articleRepository.Add(new Article { Text = articleText, Title = articleTitle, Author = articleAuthor }); IList <Article> articles = articleRepository.GetAll(); Assert.NotNull(articles); Assert.AreEqual(2, articles.Count); Assert.IsTrue(articles.Any(x => x.Title == articleTitle)); }
/// <summary> /// /// Create /// /// Right = Admin, Instructor /// /// Exception = validation /// /// </summary> public bool Add(int UserId, IArticle article) { if (!UserLogic.CheckRight(UserId, Right.Admin) || UserLogic.CheckRight(UserId, Right.Instructor)) { return(false); } if (_articleRepository.GetBy(article.Name) != null) { return(false); } if (!validation(article)) { return(false); } return(_articleRepository.Add(article)); }
public void CanDeleteArticlesFromPostgre() { var articleRepository = new ArticleRepository(dbConnectionString); var articleText = "Test Text"; var articleTitle = "Test Title"; var articleAuthor = "Bob"; articleRepository.Add(new Article { Text = articleText, Title = articleTitle, Author = articleAuthor }); Article article = articleRepository.GetAll().LastOrDefault(); Assert.NotNull(article); articleRepository.Delete(article.Id); article = articleRepository.Get(article.Id).Value; Assert.IsNull(article); }
public void Add_Returns_1_When_Adding_Valid_Product() { var databaseName = Guid.NewGuid().ToString(); using (var context = DbContextFactory.CreateInstance(databaseName)) { //Arrange var productRepository = new ProductRepository(context); var articleRepository = new ArticleRepository(context); //Act var product = ProductFactory.CreateValidEntity(); productRepository.Add(product); var article = ArticleFactory.CreateValidEntity(product); articleRepository.Add(article); var result = context.SaveChanges(); //Assert Assert.AreEqual(2, result); //Because we added two entities } }
public void Get_Returns_Product_When_Found() { var databaseName = Guid.NewGuid().ToString(); using (var context = DbContextFactory.CreateInstance(databaseName)) { //Arrange var productRepository = new ProductRepository(context); var articleRepository = new ArticleRepository(context); var product = ProductFactory.CreateValidEntity(); productRepository.Add(product); var articleToAdd = ArticleFactory.CreateValidEntity(product); articleRepository.Add(articleToAdd); context.SaveChanges(); //Act var article = articleRepository.Get(articleToAdd.Id); //Assert Assert.IsNotNull(article); } }
public int Add(Article model) { model.ContentLevel = (int)ContentLevel.Common; model.PublishStatus = (int)PublishStatus.Not; var time = DateTime.Now; model.DisplayCreatedTime = time; model.UrlTitleNum = MD5Helper.MD5ToNum(model.UrlTitle).ToString(); if (ContextUser.IsLogined) { model.CreateUser = ContextUser.Email; } model.CreatedTime = time; model.UpdateTime = time; model.Enable = 1; var id = _articleRepository.Add(model); return(id); }
public async Task Create() { display("Method Create begin working"); var parserHelper = new ParserHelper(_options); display("Method Create begin parsing articles"); var articles = await parserHelper.GetArticles(); display("Method Create finish parsing articles"); display("Method Create begin refresh articles in database"); using (_context) { foreach (var article in articles) { var dbArticle = _articleRepository.GetArticleForUrl(article.Url); if (dbArticle == null) { _articleRepository.Add(article); } } _repository.SaveChanges(); } display("Method Create finish refresh articles in database"); }
public void Remove_Throws_Exception_When_Not_Found() { var databaseName = Guid.NewGuid().ToString(); using (var context = DbContextFactory.CreateInstance(databaseName)) { //Arrange var productRepository = new ProductRepository(context); var articleRepository = new ArticleRepository(context); var product = ProductFactory.CreateValidEntity(); productRepository.Add(product); var articleToAdd = ArticleFactory.CreateValidEntity(product); articleRepository.Add(articleToAdd); context.SaveChanges(); //Act articleRepository.Remove(Guid.NewGuid()); context.SaveChanges(); //Assert } }
public void CanAddArticleToPostgre() { var articleRepository = new ArticleRepository(dbConnectionString); var articleText = "Test Text"; var articleTitle = "Test Title"; var articleAuthor = "Bob"; articleRepository.Add(new Article { Text = articleText, Title = articleTitle, Author = articleAuthor }); List <Article> articles = articleRepository.GetAll(); Assert.IsNotEmpty(articles); var article = articleRepository.Get(articles.First().Id).Value; Assert.AreEqual(articleText, article.Text); Assert.AreEqual(articleTitle, article.Title); Assert.AreEqual(articleAuthor, article.Author); }
public async Task <CreateArticleCommandResponse> Handle(CreateArticleCommand request, CancellationToken cancellationToken) { CreateArticleCommandResponse response = new CreateArticleCommandResponse() { IsSuccessful = false }; try { List <Articles> articlesDetails = new List <Articles>(); List <TaxTags> taxTagsDetails = new List <TaxTags>(); ResourceGroups ResourceGroupsDetails = new ResourceGroups(); Provinces ProvincesDetails = new Provinces(); Disclaimers DisclaimersDetails = new Disclaimers(); List <Articles> rarticles = _ArticleRepository.getArticlesListById(request.RelatedArticles); List <Articles> rresources = _ArticleRepository.getArticlesListById(request.RelatedResources); List <TaxTags> rtaxTags = _ArticleRepository.getTaxTagsDetailsByIds(request.RelatedTaxTags); List <Countries> rcountries = _ArticleRepository.getCountriesByIds(request.RelatedCountries); List <CountryGroups> rcountryGroups = _ArticleRepository.getCountryGroupsByIds(request.RelatedCountryGroups); List <Contacts> rcontacts = _ArticleRepository.getContactsByIds(request.RelatedContacts); Articles _article = new Articles(); using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { _article.Type = request.Type; _article.Author = request.Author; _article.PublishedDate = request.PublishedDate.Value; _article.SubType = request.SubType; _article.ResourceGroupId = request.ResourceGroupId > 0 ? request.ResourceGroupId : (int?)null; _article.ResourcePosition = request.ResourcePosition > 0 ? request.ResourcePosition : (int?)null; _article.IsPublished = request.IsPublished; _article.CreatedDate = DateTime.UtcNow; _article.UpdatedDate = DateTime.UtcNow; _article.ArticleContents = new List <ArticleContents>(); _article.CreatedBy = request.UpdatedBy; _article.UpdatedBy = request.UpdatedBy; _article.DisclaimerId = request.DisclaimerId; _article.ImageId = request.ImageId; _article.State = request.State; _article.ProvinceId = request.ProvinceId; foreach (var acontent in request.ArticleContent) { ArticleContents ac = new ArticleContents() { LanguageId = acontent.LanguageId, Content = acontent.Content, TeaserText = acontent.TeaserText, Title = acontent.Title }; _article.ArticleContents.Add(ac); } if (request.RelatedArticles != null) { // var rArticleList = request.RelatedArticles; // var relatedArticles = rarticles.Where(a => rArticleList.Any(ra => ra == a.ArticleId)).ToList(); foreach (Articles article in rarticles) { _article.RelatedArticlesArticle.Add(new RelatedArticles() { RelatedArticleId = article.ArticleId, Article = article }); } ; //Add reverse relation //relatedArticles.ForEach(a => a.RelatedArticlesArticle.Add(new RelatedArticles {Article = Article })); } if (request.RelatedResources != null) { // var rResourceList = request.RelatedResources.ToList(); // var relatedResources = articles.Where(a => rResourceList.Contains(a.ArticleId)).ToList(); foreach (Articles article in rresources) { _article.RelatedResourcesArticle.Add(new RelatedResources() { RelatedArticleId = article.ArticleId, Article = article }); } ; } if (request.RelatedTaxTags != null) { // var rTagList = request.RelatedTaxTags.ToList(); //var relatedTags = taxTags.Where(t => rTagList.Contains(t.TaxTagId)).ToList(); foreach (TaxTags tags in rtaxTags) { _article.ArticleRelatedTaxTags.Add(new ArticleRelatedTaxTags() { TaxTagId = tags.TaxTagId, TaxTag = tags }); } ; } if (request.RelatedCountries != null) { // var rCountries = request.RelatedCountries.ToList(); // var relatedCountries = countries.Where(c => rCountries.Contains(c.CountryId)).ToList(); foreach (Countries country in rcountries) { _article.ArticleRelatedCountries.Add(new ArticleRelatedCountries() { CountryId = country.CountryId, Country = country }); } ; } if (request.RelatedCountryGroups != null) { // var rCountryGroups = request.RelatedCountryGroups.ToList(); // var relatedCountryGroups = countryGroups.Where(c => rCountryGroups.Contains(c.CountryGroupId)).ToList(); foreach (CountryGroups cGroup in rcountryGroups) { _article.ArticleRelatedCountryGroups.Add(new ArticleRelatedCountryGroups() { CountryGroupId = cGroup.CountryGroupId, CountryGroup = cGroup }); } ; } if (request.RelatedContacts != null) { foreach (Contacts rcontact in rcontacts) { _article.ArticleRelatedContacts.Add(new ArticleRelatedContacts() { ContactId = rcontact.ContactId, Contact = rcontact }); } ; } //Push logic needs to be implemented int userCount = _ArticleRepository.SendNotificationsForArticle <CreateArticleCommand>(request); if (userCount > 0) { _article.NotificationSentDate = DateTime.Now; } _ArticleRepository.Add(_article); await _ArticleRepository.UnitOfWork .SaveEntitiesAsync(); articlesDetails = _ArticleRepository.getArticleCompleteDataById(_article.RelatedArticlesArticle.Select(s => s.RelatedArticleId).ToList()); taxTagsDetails = _ArticleRepository.getTaxTagsDetailsByIds(_article.ArticleRelatedTaxTags.Select(s => s.TaxTagId).ToList()); ResourceGroupsDetails = _article.ResourceGroupId == null ? null : _ArticleRepository.getResourceGroupById(int.Parse(_article.ResourceGroupId.ToString())); ProvincesDetails = _article.ProvinceId == null ? null : _ArticleRepository.getProvisionsById(int.Parse(_article.ProvinceId.ToString())); DisclaimersDetails = _article.DisclaimerId == null ? null : _ArticleRepository.getDisclaimerById(int.Parse(_article.DisclaimerId.ToString())); response.IsSuccessful = true; scope.Complete(); } using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { foreach (var content in _article.ArticleContents) { var DisclaimerLanguageId = DisclaimersDetails.DisclaimerContents.Where(d => d.LanguageId == content.LanguageId).Count() > 0 ? content.LanguageId : 37; var ResourceGroupLanguageId = ResourceGroupsDetails.ResourceGroupContents.Where(d => d.LanguageId == content.LanguageId).Count() > 0 ? content.LanguageId : 37; var ProvisionsLanguageId = ProvincesDetails.ProvinceContents.Where(d => d.LanguageId == content.LanguageId).Count() > 0 ? content.LanguageId : 37; var eventSourcing = new ArticleCommandEvent() { EventType = ServiceBusEventType.Create, ArticleId = _article.ArticleId, PublishedDate = _article.PublishedDate == null?"": _article.PublishedDate.ToString(), Author = _article.Author == null ? "" : _article.Author, ImageId = _article.ImageId == null ? -1 : _article.ImageId, State = _article.State == null ? "" : _article.State, Type = _article.Type == null ? -1 : _article.Type, SubType = _article.SubType == null ? -1 : _article.SubType, ResourcePosition = _article.ResourcePosition == null ? -1 : _article.ResourcePosition, Disclaimer = new DisclamersSchema { DisclaimerId = int.Parse(_article.DisclaimerId.ToString()), ProviderName = DisclaimersDetails.DisclaimerContents.Where(d => d.LanguageId == DisclaimerLanguageId).Select(ds => ds.ProviderName == null ? "" : ds.ProviderName).FirstOrDefault(), ProviderTerms = DisclaimersDetails.DisclaimerContents.Where(d => d.LanguageId == DisclaimerLanguageId).Select(ds => ds.ProviderTerms == null ? "" : ds.ProviderTerms).FirstOrDefault() }, ResourceGroup = new ResourceGroupsSchema { ResourceGroupId = int.Parse(_article.ResourceGroupId.ToString()), GroupName = ResourceGroupsDetails.ResourceGroupContents.Where(d => d.LanguageId == ResourceGroupLanguageId).Select(ds => ds.GroupName == null ? "" : ds.GroupName).FirstOrDefault(), Position = ResourceGroupsDetails.Position == null ? -1 : ResourceGroupsDetails.Position }, IsPublished = _article.IsPublished == null ? false : _article.IsPublished, CreatedDate = _article.CreatedDate == null ? "" : _article.CreatedDate.ToString(), CreatedBy = _article.CreatedBy == null ? "" : _article.CreatedBy, UpdatedDate = _article.UpdatedDate == null ? "" : _article.UpdatedDate.ToString(), UpdatedBy = _article.UpdatedBy == null ? "" : _article.UpdatedBy, NotificationSentDate = _article.NotificationSentDate == null ? "" : _article.NotificationSentDate.ToString(), Provinces = new ProvinceSchema { ProvinceId = int.Parse(_article.ProvinceId.ToString()), DisplayName = ProvincesDetails.ProvinceContents.Where(d => d.LanguageId == ProvisionsLanguageId).Select(ds => ds.DisplayName == null ? "" : ds.DisplayName).FirstOrDefault() }, ArticleContentId = content.ArticleContentId == null ? -1 : content.ArticleContentId, LanguageId = content.LanguageId == null ? -1 : content.LanguageId, Title = content.Title == null ? "" : content.Title, TitleInEnglishDefault = _article.ArticleContents.Where(l => l.LanguageId == 37 && l.ArticleId == content.ArticleId).Select(s => { if (s.Title == null) { return(""); } else { return(s.Title); } }).FirstOrDefault(), TeaserText = content.TeaserText == null ? "" : content.TeaserText, Content = content.Content == null ? "" : content.Content, RelatedContacts = _article.ArticleRelatedContacts.Select(s => new RelatedEntityId { IdVal = s.ContactId }).ToList(), RelatedCountries = _article.ArticleRelatedCountries.Select(s => new RelatedEntityId { IdVal = s.CountryId }).ToList(), RelatedCountryGroups = _article.ArticleRelatedCountryGroups.Select(s => new RelatedEntityId { IdVal = s.CountryGroupId }).ToList(), RelatedTaxTags = _article.ArticleRelatedTaxTags.Select(s => { var RelatedtaxTagLanguageId = taxTagsDetails.Where(td => td.TaxTagId == s.TaxTagId).FirstOrDefault().TaxTagContents.Where(ttc => ttc.LanguageId == content.LanguageId).Count() > 0 ? content.LanguageId : 37; return(new RelatedTaxTagsSchema { TaxTagId = s.TaxTagId, DisplayName = taxTagsDetails.Where(td => td.TaxTagId == s.TaxTagId).FirstOrDefault().TaxTagContents.Where(ttc => ttc.LanguageId == RelatedtaxTagLanguageId).Select(ttcs => ttcs.DisplayName == null ? "" : ttcs.DisplayName).FirstOrDefault() }); }).ToList(), RelatedArticles = _article.RelatedArticlesArticle.Select(s => { var RelatedArticleLanguageId = articlesDetails.Where(ra => ra.ArticleId.Equals(s.RelatedArticleId)).FirstOrDefault().ArticleContents.Where(ttc => ttc.LanguageId == content.LanguageId).Count() > 0 ? content.LanguageId : 37; return(new RelatedArticlesSchema { ArticleId = s.RelatedArticleId, PublishedDate = articlesDetails.Where(ra => ra.ArticleId.Equals(s.RelatedArticleId)).Select(v => v.PublishedDate == null ? "" : v.PublishedDate.ToString()).FirstOrDefault(), Title = articlesDetails.Where(ra => ra.ArticleId.Equals(s.RelatedArticleId)).FirstOrDefault().ArticleContents.Where(ttc => ttc.LanguageId == RelatedArticleLanguageId).Select(v => v.Title == null ? "" : v.Title).FirstOrDefault().ToString(), CountryId = articlesDetails.Where(ad => ad.ArticleId.Equals(s.RelatedArticleId)).FirstOrDefault().ArticleRelatedCountries.Select(arc => new RelatedEntityId { IdVal = arc.CountryId }).ToList() }); }).ToList(), RelatedResources = _article.RelatedResourcesArticle.Select(s => { var RelatedResourceLanguageId = articlesDetails.Where(ra => ra.ArticleId.Equals(s.RelatedArticleId)).FirstOrDefault().ArticleContents.Where(ttc => ttc.LanguageId == content.LanguageId).Count() > 0 ? content.LanguageId : 37; return(new RelatedArticlesSchema { ArticleId = s.RelatedArticleId, PublishedDate = articlesDetails.Where(ra => ra.ArticleId.Equals(s.RelatedArticleId)).Select(v => v.PublishedDate == null ? "" : v.PublishedDate.ToString()).FirstOrDefault(), Title = articlesDetails.Where(ra => ra.ArticleId.Equals(s.RelatedArticleId)).FirstOrDefault().ArticleContents.Where(ttc => ttc.LanguageId == RelatedResourceLanguageId).Select(v => v.Title == null ? "" : v.Title).FirstOrDefault().ToString(), CountryId = articlesDetails.Where(ad => ad.ArticleId.Equals(s.RelatedArticleId)).FirstOrDefault().ArticleRelatedCountries.Select(arc => new RelatedEntityId { IdVal = arc.CountryId }).ToList() }); }).ToList(), Discriminator = Constants.ArticlesDiscriminator, PartitionKey = "" }; await _Eventcontext.PublishThroughEventBusAsync(eventSourcing); } scope.Complete(); } return(response); } catch (Exception ex) { response.IsSuccessful = false; response.FailureReason = "Technical Error"; // _logger.LogError(ex, "Error while handling command"); } return(response); }
//[AutoValidateAntiforgeryToken] public IActionResult Update() { dynamic obj = null; (bool, string)IsSuccess = (false, ""); string typeId = Request.Form["typeId"].ToString(), action = Request.Form["action"].ToString(); if (string.IsNullOrEmpty(typeId) || string.IsNullOrEmpty(action)) { obj = new { code = 0, tid = -1, msg = "请求异常" }; return(Json(obj)); } switch (typeId) { #region 分类添加和修改 case "1": var caidStr = Request.Form["CategoryId"].ToString(); var caName = Request.Form["CategoryName"].ToString(); if (!string.IsNullOrEmpty(caName)) { if (!string.IsNullOrEmpty(action)) { if (action == "1") { if (!int.TryParse(caidStr, out var id)) { obj = new { code = 0, tid = typeId, msg = "分类Id转换错误" }; return(Json(obj)); } var m = new Model.BlogCategory { CategoryId = id, CategoryName = caName }; IsSuccess = _categoryService.Update(m); } if (action == "0") { var m = new Model.BlogCategory { CategoryName = caName }; IsSuccess = _categoryService.Add(m); } } if (IsSuccess.Item1) { obj = new { code = 0, tid = typeId, msg = IsSuccess.Item2 }; } else { obj = new { code = 1, tid = typeId, msg = IsSuccess.Item2 }; } } else { obj = new { code = 2, tid = typeId, msg = "请求失败" }; } break; #endregion #region 文章添加和修改 case "2": var artidStr = Request.Form["ArticleId"].ToString(); var artName = Request.Form["ArticleName"].ToString(); var ar_caidStr = Request.Form["CategoryId"].ToString(); var tagName = Request.Form["TagName"].ToString(); var tagidStr = Request.Form["TagId"].ToString(); var body = Request.Form["body"].ToString(); var remark = Request.Form["remark"].ToString(); var TitileImgPath = Request.Form["TitleImgPath"].ToString(); if (!string.IsNullOrEmpty(artName) && !string.IsNullOrEmpty(body) && !string.IsNullOrEmpty(artName) && !string.IsNullOrEmpty(TitileImgPath)) { if (!string.IsNullOrEmpty(action)) { if (!int.TryParse(ar_caidStr, out var caid)) { obj = new { code = 0, tid = typeId, msg = "分类Id转换错误" }; return(Json(obj)); } if (action == "1") { if (!int.TryParse(artidStr, out var artid)) { obj = new { code = 0, tid = typeId, msg = "文章Id转换错误" }; return(Json(obj)); } Model.BlogTag tg = null; if (int.TryParse(tagidStr, out var tgid)) { tg = new Model.BlogTag { TagId = tgid, ArId = artid, TagName = tagName ?? tagName.Trim() }; } var m = new Model.BlogArticle { ArticleId = artid, ArticleName = artName, Body = body, Remark = remark, IsPublished = true, PostDate = DateTime.Now, Category = _categoryService.Get(caid), Tag = tg, TitleImgPath = TitileImgPath }; IsSuccess = _articleService.Update(m); } if (action == "0") { var m = new Model.BlogArticle { ArticleName = artName, Body = body, Remark = remark, IsPublished = true, PostDate = DateTime.Now, Category = _categoryService.Get(caid), Tag = new Model.BlogTag { TagName = tagName }, TitleImgPath = TitileImgPath }; IsSuccess = _articleService.Add(m); } } if (IsSuccess.Item1) { obj = new { code = 0, tid = typeId, msg = IsSuccess.Item2 }; } else { obj = new { code = 1, tid = typeId, msg = IsSuccess.Item2 }; } } else { obj = new { code = 2, tid = typeId, msg = "请求失败" }; } break; default: obj = new { code = 2, tid = -1, msg = "请求异常" }; break; #endregion } return(Json(obj)); }