public ActionResult Delete(int?id, FormCollection collection)
 {
     try
     {
         ArticleRepository ml = new ArticleRepository();
         if (id != null && id > 0)
         {
             ml.Delete(id ?? 0);
         }
         else
         {
             if (string.IsNullOrEmpty(collection["IDs"]))
             {
                 return(Content("未指定删除对象ID"));
             }
             string[] ids = collection["IDs"].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
             foreach (string item in ids)
             {
                 ml.Delete(int.Parse(item));
             }
         }
         return(Content("1"));
     }
     catch (Exception ex)
     {
         return(Content(ErrorWirter(RouteData, ex.Message)));
     }
 }
Esempio n. 2
0
        public async Task <IActionResult> Delete(int?id)
        {
            var article = _articleRepository.Get(a => a.ID == id);

            _articleRepository.Delete(article);

            return(RedirectToAction(nameof(List)));
        }
Esempio n. 3
0
        public void TryDeleteNotExistArticlesFromPostgreNotThrowTheError()
        {
            var articleRepository = new ArticleRepository(dbConnectionString);
            var articleId         = Guid.NewGuid();

            Assert.DoesNotThrow(() => articleRepository.Delete(articleId));
        }
        private void Consumer_RabbitReceived(RabbitMqMessage message, string consumer)
        {
            switch (message.Action)
            {
            case RabbitMqAction.GetAll:

                RabbitMqMessage getall = new RabbitMqMessage()
                {
                    Action = RabbitMqAction.Data,
                    Data   = articleRepository.Get()
                };

                this.consumer.Send(message.Sender + ".exchange", getall);
                Console.WriteLine("RabbitMQ: Articles Returned.");
                break;

            case RabbitMqAction.Delete:
                Article article = JsonConvert.DeserializeObject <Article>(message.Data.ToString());
                articleRepository.Delete(article.Id);
                Console.WriteLine("RabbitMQ: Article Deleted.");
                break;

            default:
                Console.WriteLine("Unknown RabbitMQ Message.");
                break;
            }
        }
Esempio n. 5
0
        public ActionResult Delete(int id)
        {
            //TODO: Tag' Delete Code

            result.resultint = repoArt.Delete(id);
            return(RedirectToAction("InActiveList"));
        }
Esempio n. 6
0
        public ResponseMessage Delete(int id)
        {
            ResponseMessage response = new ResponseMessage();

            _repository.Delete(id);

            return(response);
        }
Esempio n. 7
0
        public async Task <IActionResult> DeleteArticle(string articleId)
        {
            ArticleModel article = _articleRepository.Get(new Guid(articleId));

            if (article != null)
            {
                _articleRepository.Delete(new Guid(articleId));
            }
            return(RedirectPermanent("~/ArticleManage/ArticleTable?userId=" + article.UserId));
        }
Esempio n. 8
0
        public async Task DeleteArticle(string id)
        {
            var article = await _articleRepository.GetById(id);

            if (article == null)
            {
                throw new BusinessException("文章不存在!");
            }

            await _articleRepository.Delete(id);
        }
Esempio n. 9
0
 public ActionResult DeleteArticle(int id)
 {
     if (AuthenticationManager.LoggedUser.GetType().BaseType.Equals(typeof(Teacher)))
     {
         Article           article           = new Article();
         ArticleRepository articleRepository = new ArticleRepository();
         article = articleRepository.GetById(id);
         articleRepository.Delete(article);
         return(RedirectToAction("Articles"));
     }
     return(RedirectToAction("Articles"));
 }
 public ActionResult Delete(int id, Article article)
 {
     try
     {
         dbArticles.Delete(id);
         return(RedirectToAction("List"));
     }
     catch
     {
         return(PartialView());
     }
 }
Esempio n. 11
0
 public ActionResult Delete(int id, Article article)
 {
     try
     {
         articleRepository.Delete(id);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Esempio n. 12
0
        public IActionResult DeleteArticleById(int id)
        {
            Article article = (from a in _articleRepository.Get()
                               where a.Id == id
                               select a)
                              .SingleOrDefault();

            if (null != article)
            {
                _articleRepository.Delete(article);
                _articleRepository.Save();
            }
            return(Ok());
        }
Esempio n. 13
0
        protected void rptMakaleler_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            switch (e.CommandName)
            {
            case "delete":
                ar.Delete(Convert.ToInt32(e.CommandArgument));
                Articlefill();
                break;

            case "update":
                Response.Redirect(string.Format("~/AdminPanel/Article/ArticleUpdate.aspx?ArticleId={0}", e.CommandArgument));
                break;
            }
        }
Esempio n. 14
0
        public IActionResult Delete()
        {
            string  id     = Request.Form["id"];
            string  typeId = Request.Form["typeId"];
            dynamic obj    = null;

            switch (typeId)
            {
            case "1":
                if (!string.IsNullOrEmpty(id))
                {
                    var m = _categoryService.Get(Convert.ToInt32(id));
                    var(IsDelete, msg) = _categoryService.Delete(m);
                    if (IsDelete)
                    {
                        obj = new { code = 0, msg = "删除成功" };
                    }
                    else
                    {
                        obj = new { code = 1, msg = "删除失败" };
                    }
                }
                else
                {
                    obj = new { code = 2, msg = "请求失败" };
                }
                break;

            case "2":
                if (!string.IsNullOrEmpty(id))
                {
                    var m = _articleService.Get(Convert.ToInt32(id));
                    var(IsDelete, msg) = _articleService.Delete(m);
                    if (IsDelete)
                    {
                        obj = new { code = 0, msg = "删除成功" };
                    }
                    else
                    {
                        obj = new { code = 1, msg = "删除失败" };
                    }
                }
                else
                {
                    obj = new { code = 2, msg = "请求失败" };
                }
                break;
            }
            return(Json(obj));
        }
Esempio n. 15
0
        /// <summary>
        ///
        ///     Delete
        ///
        ///     Right    = Admin, Instructor
        ///
        ///     Exception        = Must exist
        ///
        /// </summary>
        public bool Delete(int userId, int id)
        {
            if (!UserLogic.CheckRight(userId, Right.Admin) || UserLogic.CheckRight(userId, Right.Instructor))
            {
                return(false);
            }


            if (_articleRepository.GetBy(id) == null)
            {
                return(false);
            }


            return(_articleRepository.Delete(id));
        }
 public IHttpActionResult DeleteArticle(int id)
 {
     try
     {
         ArticleDTO dto = Repository.GetAsNoTracking(d => d.Id == id).First().DTO;
         Repository.Delete(id);
         return(Ok(dto));
     }
     catch (NullReferenceException nre)
     {
         return(NotFound());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Esempio n. 17
0
 public ActionResult Delete(int id)
 {
     try
     {
         ArticleRepository ml = new ArticleRepository();
         if (id > 0)
         {
             ml.Delete(id);
         }
         else
         {
             return(Content("未指定删除对象ID"));
         }
         return(Content("1"));
     }
     catch (Exception ex)
     {
         return(Content(ErrorWirter(RouteData, ex.Message)));
     }
 }
Esempio n. 18
0
        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);
        }
Esempio n. 19
0
 public void Delete(int articleId)
 {
     repo.Delete(articleId);
 }
Esempio n. 20
0
 public /*async*/ void Delete(int id)
 {
     /*await*/ articleRepository.Delete(id);
 }
Esempio n. 21
0
 public ActionResult DeleteArticle(int id)
 {
     article_repo.Delete(article_repo.GetByID(id));
     return(RedirectToAction("ListArticle"));
 }
Esempio n. 22
0
 public virtual void Remove(Guid id)
 {
     _articleRepository.Delete(id);
 }
Esempio n. 23
0
 public void Delete(Article entity)
 => _articleRepository.Delete(entity);
        public async Task <UpdateArticleCommandResponse> Handle(UpdateArticleCommand request, CancellationToken cancellationToken)
        {
            UpdateArticleCommandResponse response = new UpdateArticleCommandResponse()
            {
                IsSuccessful = false
            };

            try
            {
                Disclaimers     DisclaimersDetails    = new Disclaimers();
                ResourceGroups  ResourceGroupsDetails = new ResourceGroups();
                Provinces       ProvincesDetails      = new Provinces();
                List <TaxTags>  taxTagsDetails        = new List <TaxTags>();
                List <Articles> articlesDetails       = new List <Articles>();
                Articles        _article = _ArticleRepository.getArticleCompleteDataById(new List <int> {
                    request.ArticleID
                })[0];
                var contentToDelete = new List <int>();
                using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    _article.UpdatedBy        = request.UpdatedBy;
                    _article.UpdatedDate      = DateTime.UtcNow;
                    _article.Author           = request.Author;
                    _article.DisclaimerId     = request.DisclaimerId;
                    _article.ResourceGroupId  = request.ResourceGroupId > 0 ? request.ResourceGroupId : (int?)null;
                    _article.ResourcePosition = request.ResourcePosition > 0 ? request.ResourcePosition : (int?)null;

                    if (request.PublishedDate != null)
                    {
                        _article.PublishedDate = request.PublishedDate.Value;
                    }
                    _article.SubType     = request.SubType;
                    _article.State       = request.State;
                    _article.ProvinceId  = request.ProvinceId;
                    _article.IsPublished = request.IsPublished;//= Action == "Publish";
                    //update article content
                    //delete removed languages, update existing, add new languages
                    foreach (var content in request.ArticleContent)
                    {
                        var artContent =
                            _article.ArticleContents.FirstOrDefault(v => v.LanguageId == content.LanguageId);
                        if (artContent == null)
                        {
                            var newContent = new ArticleContents
                            {
                                Content    = content.Content,
                                LanguageId = content.LanguageId,
                                TeaserText = content.TeaserText,
                                Title      = content.Title
                            };

                            //content.ArticleId = articleobject.ArticleId;
                            _article.ArticleContents.Add(newContent);
                        }
                        else
                        {
                            artContent.Content    = content.Content;
                            artContent.LanguageId = content.LanguageId;
                            artContent.TeaserText = content.TeaserText;
                            artContent.Title      = content.Title;
                            _ArticleRepository.Update <ArticleContents>(artContent);
                        }
                    }
                    var articleContentIds = _article.ArticleContents.Select(c => c.LanguageId).ToList();
                    var articleDtoCids    = request.ArticleContent.Select(c => c.LanguageId).ToList();
                    var removedContents   = articleContentIds.Except(articleDtoCids);
                    _article.ArticleContents.Where(a => removedContents.Contains(a.LanguageId)).ToList().ForEach(removed =>
                    {
                        _ArticleRepository.Delete <ArticleContents>(removed);
                        _article.ArticleContents.Remove(removed);
                        contentToDelete.Add((int)removed.LanguageId);
                    });

                    // Update Related Countries
                    foreach (var country in request.RelatedCountries)
                    {
                        var articleCountry =
                            _article.ArticleRelatedCountries
                            .FirstOrDefault(c => c.CountryId == country);
                        if (articleCountry != null)
                        {
                            continue;
                        }
                        var newCountry = _ArticleRepository.getCountryById(country);
                        _article.ArticleRelatedCountries.Add(new ArticleRelatedCountries {
                            Country = newCountry, CountryId = newCountry.CountryId
                        });
                    }
                    var articleCountries = _article.ArticleRelatedCountries.Select(c => c.CountryId).ToList();
                    var dtoCountries     = request.RelatedCountries;
                    var removedCountries = articleCountries.Except(dtoCountries);
                    _article.ArticleRelatedCountries.Where(a => removedCountries.Contains(a.CountryId))
                    .ToList()
                    .ForEach(removed => { _article.ArticleRelatedCountries.Remove(removed); });

                    // Update Related Country Groups
                    foreach (var countryGroup in request.RelatedCountryGroups)
                    {
                        var articleCountryGroup =
                            _article.ArticleRelatedCountryGroups
                            .FirstOrDefault(c => c.CountryGroupId == countryGroup);
                        if (articleCountryGroup != null)
                        {
                            continue;
                        }
                        var newCountryGroup = _ArticleRepository.getCountryGroupById(countryGroup);
                        _article.ArticleRelatedCountryGroups.Add(new ArticleRelatedCountryGroups {
                            CountryGroup = newCountryGroup, CountryGroupId = newCountryGroup.CountryGroupId
                        });
                    }
                    var articleCountryGroups = _article.ArticleRelatedCountryGroups.Select(c => c.CountryGroupId).ToList();
                    var dtoCountryGroups     = request.RelatedCountryGroups;
                    var removedCountryGroups = articleCountryGroups.Except(dtoCountryGroups);
                    _article.ArticleRelatedCountryGroups.Where(a => removedCountryGroups.Contains(a.CountryGroupId))
                    .ToList()
                    .ForEach(removed => { _article.ArticleRelatedCountryGroups.Remove(removed); });

                    //update related articles
                    if (request.RelatedArticles != null)
                    {
                        var relatedArticles    = _article.RelatedArticlesArticle.Select(c => c.ArticleId).ToList();
                        var dtoRelatedArticles = request.RelatedArticles;

                        var addRelatedArticles = dtoRelatedArticles.Except(relatedArticles);
                        var newRelatedArticles = _ArticleRepository.getArticlesListById(addRelatedArticles.ToList());// context.Articles.Where(a => addRelatedArticles.Contains(a.ArticleId));
                        newRelatedArticles.ForEach(a =>
                        {
                            _article.RelatedArticlesArticle.Add(new RelatedArticles {
                                Article = a, RelatedArticleId = a.ArticleId
                            });
                            //Reverse relation
                            //if (!a.RelatedArticlesArticle.Any(r => r.ArticleId == _article.ArticleId))
                            //{
                            //    a.RelatedArticlesArticle.Add(new RelatedArticles { Article = _article, RelatedArticleId = _article.ArticleId });
                            //}
                        });

                        var removedRelatedArticles = relatedArticles.Except(dtoRelatedArticles);
                        _article.RelatedArticlesArticle.Where(a => removedRelatedArticles.Contains(a.ArticleId))
                        .ToList()
                        .ForEach(removed =>
                        {
                            _article.RelatedArticlesArticle.Remove(removed);
                        });
                    }

                    // update related resources
                    if (request.RelatedResources != null)
                    {
                        foreach (var rResource in request.RelatedResources)
                        {
                            var relatedRes =
                                _article.RelatedResourcesArticle.FirstOrDefault(c => c.RelatedArticleId == rResource);
                            if (relatedRes != null)
                            {
                                continue;
                            }
                            var newRelatedResource = _ArticleRepository.getArticleDataById(rResource);
                            _article.RelatedResourcesArticle.Add(new RelatedResources {
                                Article = newRelatedResource, RelatedArticleId = newRelatedResource.ArticleId
                            });
                        }
                        var relatedResources        = _article.RelatedResourcesArticle.Select(c => c.RelatedArticleId).ToList();
                        var dtoRelatedResources     = request.RelatedResources;
                        var removedRelatedResources = relatedResources.Except(dtoRelatedResources);
                        _article.RelatedResourcesArticle.Where(a => removedRelatedResources.Contains(a.RelatedArticleId))
                        .ToList()
                        .ForEach(removed => { _article.RelatedResourcesArticle.Remove(removed); });
                    }

                    //update related tags
                    if (request.RelatedTaxTags != null)
                    {
                        foreach (var rTag in request.RelatedTaxTags)
                        {
                            var relatedTag =
                                _article.ArticleRelatedTaxTags.FirstOrDefault(c => c.TaxTagId == rTag);
                            if (relatedTag == null)
                            {
                                var newTag = _ArticleRepository.getTaxTagsById(rTag);
                                _article.ArticleRelatedTaxTags.Add(new ArticleRelatedTaxTags {
                                    TaxTag = newTag, TaxTagId = newTag.TaxTagId
                                });
                            }
                        }
                        var relatedTags = _article.ArticleRelatedTaxTags.Select(c => c.TaxTagId).ToList();
                        var dtoTags     = request.RelatedTaxTags;
                        var removedTags = relatedTags.Except(dtoTags);
                        _article.ArticleRelatedTaxTags.Where(a => removedTags.Contains(a.TaxTagId))
                        .ToList()
                        .ForEach(removed => { _article.ArticleRelatedTaxTags.Remove(removed); });
                    }

                    //update related contacts
                    if (request.RelatedContacts != null)
                    {
                        foreach (var dtoContact in request.RelatedContacts)
                        {
                            var relatedContact = _article.ArticleRelatedContacts.FirstOrDefault(c => c.ContactId == dtoContact);
                            if (relatedContact == null)
                            {
                                var newContact = _ArticleRepository.getContactsById(dtoContact);// context.Contacts.FirstOrDefault(c => c.ContactId == dtoContact.ContactId);
                                _article.ArticleRelatedContacts.Add(new ArticleRelatedContacts {
                                    Contact = newContact, ContactId = newContact.ContactId
                                });
                            }
                        }
                        var relatedContacts = _article.ArticleRelatedContacts.Select(c => c.ContactId).ToList();
                        var dtoContacts     = request.RelatedContacts;
                        var removeContacts  = relatedContacts.Except(dtoContacts);
                        _article.ArticleRelatedContacts.Where(a => removeContacts.Contains(a.ContactId))
                        .ToList()
                        .ForEach(removeContact => _article.ArticleRelatedContacts.Remove(removeContact));
                    }

                    //update image
                    _article.ImageId = request.ImageId;
                    //Push logic needs to be implemented
                    int userCount = _ArticleRepository.SendNotificationsForArticle <UpdateArticleCommand>(request);
                    if (userCount > 0)
                    {
                        _article.NotificationSentDate = DateTime.Now;
                    }
                    await _ArticleRepository.UnitOfWork
                    .SaveEntitiesAsync();

                    taxTagsDetails        = _ArticleRepository.getTaxTagsDetailsByIds(_article.ArticleRelatedTaxTags.Select(s => s.TaxTagId).ToList());
                    articlesDetails       = _ArticleRepository.getArticleCompleteDataById(_article.RelatedArticlesArticle.Select(s => s.RelatedArticleId).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))
                {
                    var articleDocs = _context.GetAll(Constants.ArticlesDiscriminator);
                    foreach (var content in _article.ArticleContents)
                    {
                        foreach (var article in articleDocs.Where(ad => ad.GetPropertyValue <int>("LanguageId") == content.LanguageId))
                        {
                            foreach (var relatedArticles in article.GetPropertyValue <List <RelatedArticlesSchema> >("RelatedArticles"))
                            {
                                if (relatedArticles.ArticleId == _article.ArticleId)
                                {
                                    List <RelatedArticlesSchema> relatedArticleSchema = new List <RelatedArticlesSchema>();
                                    relatedArticleSchema = article.GetPropertyValue <List <RelatedArticlesSchema> >("RelatedArticles");

                                    var index = relatedArticleSchema.IndexOf(relatedArticleSchema.Where(i => i.ArticleId == _article.ArticleId).First());
                                    if (index != -1)
                                    {
                                        relatedArticleSchema[index] = new RelatedArticlesSchema {
                                            ArticleId = _article.ArticleId, Title = content.Title == null ? "" : content.Title, PublishedDate = _article.PublishedDate == null ? "" : _article.PublishedDate.ToString(), CountryId = _article.ArticleRelatedCountries.Select(s => new RelatedEntityId {
                                                IdVal = s.CountryId
                                            }).ToList()
                                        }
                                    }
                                    ;
                                    var eventSourcingRelated = new ArticleCommandEvent()
                                    {
                                        id = article != null?article.GetPropertyValue <Guid>("id") : Guid.NewGuid(),
                                                 EventType             = ServiceBusEventType.Update,
                                                 ArticleId             = article.GetPropertyValue <int>("ArticleId"),
                                                 PublishedDate         = article.GetPropertyValue <string>("PublishedDate"),
                                                 Author                = article.GetPropertyValue <string>("author"),
                                                 ImageId               = article.GetPropertyValue <int>("ImageId"),
                                                 State                 = article.GetPropertyValue <string>("State"),
                                                 Type                  = article.GetPropertyValue <int>("Type"),
                                                 SubType               = article.GetPropertyValue <int>("SubType"),
                                                 ResourcePosition      = article.GetPropertyValue <int>("ResourcePosition"),
                                                 Disclaimer            = article.GetPropertyValue <DisclamersSchema>("Disclaimer"),
                                                 ResourceGroup         = article.GetPropertyValue <ResourceGroupsSchema>("ResourceGroup"),
                                                 IsPublished           = article.GetPropertyValue <bool>("IsPublished"),
                                                 CreatedDate           = article.GetPropertyValue <string>("CreatedDate"),
                                                 CreatedBy             = article.GetPropertyValue <string>("CreatedBy"),
                                                 UpdatedDate           = article.GetPropertyValue <string>("UpdatedDate"),
                                                 UpdatedBy             = article.GetPropertyValue <string>("UpdatedBy"),
                                                 NotificationSentDate  = article.GetPropertyValue <string>("NotificationSentDate"),
                                                 Provinces             = article.GetPropertyValue <ProvinceSchema>("Provisions"),
                                                 ArticleContentId      = article.GetPropertyValue <int>("ArticleContentId"),
                                                 LanguageId            = article.GetPropertyValue <int>("LanguageId"),
                                                 Title                 = article.GetPropertyValue <string>("Title"),
                                                 TitleInEnglishDefault = article.GetPropertyValue <string>("TitleInEnglishDefault"),
                                                 TeaserText            = article.GetPropertyValue <string>("TeaserText"),
                                                 Content               = article.GetPropertyValue <string>("Content"),
                                                 RelatedContacts       = article.GetPropertyValue <List <RelatedEntityId> >("RelatedContacts"),
                                                 RelatedCountries      = article.GetPropertyValue <List <RelatedEntityId> >("RelatedCountries"),
                                                 RelatedCountryGroups  = article.GetPropertyValue <List <RelatedEntityId> >("RelatedCountryGroups"),
                                                 RelatedTaxTags        = article.GetPropertyValue <List <RelatedTaxTagsSchema> >("RelatedTaxTags"),
                                                 RelatedArticles       = relatedArticleSchema,
                                                 RelatedResources      = article.GetPropertyValue <List <RelatedArticlesSchema> >("RelatedResources"),
                                                 Discriminator         = article.GetPropertyValue <string>("Discriminator"),
                                                 PartitionKey          = ""
                                    };
                                    await _Eventcontext.PublishThroughEventBusAsync(eventSourcingRelated);
                                }
                            }
                        }
                        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 doc = articleDocs.FirstOrDefault(d => d.GetPropertyValue <int>("ArticleId") == _article.ArticleId &&
                                                             d.GetPropertyValue <int?>("LanguageId") == content.LanguageId);
                        var eventSourcing = new ArticleCommandEvent()
                        {
                            id = doc != null?doc.GetPropertyValue <Guid>("id") : Guid.NewGuid(),
                                     EventType        = doc != null ? ServiceBusEventType.Update : 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 == null?"-1": _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 == null ? "-1" : _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 => s.Title == null ? "" : 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().ToString(), 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().ToString(), 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);
                    }
                    foreach (int i in contentToDelete)
                    {
                        foreach (var article in articleDocs.Where(ad => ad.GetPropertyValue <int>("LanguageId") == i))
                        {
                            foreach (var relatedArticles in article.GetPropertyValue <List <RelatedArticlesSchema> >("RelatedArticles"))
                            {
                                if (relatedArticles.ArticleId == _article.ArticleId)
                                {
                                    var titleInEnglish = articleDocs.Where(ad => ad.GetPropertyValue <int>("ArticleId") == _article.ArticleId && ad.GetPropertyValue <int>("LanguageId") == 37).Select(ads => ads.GetPropertyValue <string>("Title")).FirstOrDefault();
                                    List <RelatedArticlesSchema> relatedArticleSchema = new List <RelatedArticlesSchema>();
                                    relatedArticleSchema = article.GetPropertyValue <List <RelatedArticlesSchema> >("RelatedArticles");

                                    var index = relatedArticleSchema.IndexOf(relatedArticleSchema.Where(ras => ras.ArticleId == _article.ArticleId).First());
                                    if (index != -1)
                                    {
                                        if (titleInEnglish == "")
                                        {
                                            relatedArticleSchema.Remove(relatedArticleSchema.Where(ras => ras.ArticleId == _article.ArticleId).First());
                                        }
                                        else
                                        {
                                            relatedArticleSchema[index] = new RelatedArticlesSchema {
                                                ArticleId = _article.ArticleId, Title = (titleInEnglish == null ? "" : titleInEnglish), PublishedDate = _article.PublishedDate == null ? "" : _article.PublishedDate.ToString(), CountryId = _article.ArticleRelatedCountries.Select(s => new RelatedEntityId {
                                                    IdVal = s.CountryId
                                                }).ToList()
                                            }
                                        }
                                    }
                                    ;
                                    var eventSourcingRelated = new ArticleCommandEvent()
                                    {
                                        id = article != null?article.GetPropertyValue <Guid>("id") : Guid.NewGuid(),
                                                 EventType             = ServiceBusEventType.Update,
                                                 ArticleId             = article.GetPropertyValue <int>("ArticleId"),
                                                 PublishedDate         = article.GetPropertyValue <string>("PublishedDate"),
                                                 Author                = article.GetPropertyValue <string>("author"),
                                                 ImageId               = article.GetPropertyValue <int>("ImageId"),
                                                 State                 = article.GetPropertyValue <string>("State"),
                                                 Type                  = article.GetPropertyValue <int>("Type"),
                                                 SubType               = article.GetPropertyValue <int>("SubType"),
                                                 ResourcePosition      = article.GetPropertyValue <int>("ResourcePosition"),
                                                 Disclaimer            = article.GetPropertyValue <DisclamersSchema>("Disclaimer"),
                                                 ResourceGroup         = article.GetPropertyValue <ResourceGroupsSchema>("ResourceGroup"),
                                                 IsPublished           = article.GetPropertyValue <bool>("IsPublished"),
                                                 CreatedDate           = article.GetPropertyValue <string>("CreatedDate"),
                                                 CreatedBy             = article.GetPropertyValue <string>("CreatedBy"),
                                                 UpdatedDate           = article.GetPropertyValue <string>("UpdatedDate"),
                                                 UpdatedBy             = article.GetPropertyValue <string>("UpdatedBy"),
                                                 NotificationSentDate  = article.GetPropertyValue <string>("NotificationSentDate"),
                                                 Provinces             = article.GetPropertyValue <ProvinceSchema>("Provisions"),
                                                 ArticleContentId      = article.GetPropertyValue <int>("ArticleContentId"),
                                                 LanguageId            = article.GetPropertyValue <int>("LanguageId"),
                                                 Title                 = article.GetPropertyValue <string>("Title"),
                                                 TitleInEnglishDefault = article.GetPropertyValue <string>("TitleInEnglishDefault"),
                                                 TeaserText            = article.GetPropertyValue <string>("TeaserText"),
                                                 Content               = article.GetPropertyValue <string>("Content"),
                                                 RelatedContacts       = article.GetPropertyValue <List <RelatedEntityId> >("RelatedContacts"),
                                                 RelatedCountries      = article.GetPropertyValue <List <RelatedEntityId> >("RelatedCountries"),
                                                 RelatedCountryGroups  = article.GetPropertyValue <List <RelatedEntityId> >("RelatedCountryGroups"),
                                                 RelatedTaxTags        = article.GetPropertyValue <List <RelatedTaxTagsSchema> >("RelatedTaxTags"),
                                                 RelatedArticles       = relatedArticleSchema,
                                                 RelatedResources      = article.GetPropertyValue <List <RelatedArticlesSchema> >("RelatedResources"),
                                                 Discriminator         = article.GetPropertyValue <string>("Discriminator"),
                                                 PartitionKey          = ""
                                    };
                                    await _Eventcontext.PublishThroughEventBusAsync(eventSourcingRelated);
                                }
                            }
                        }
                        var deleteEvt = new ArticleCommandEvent()
                        {
                            id = articleDocs.FirstOrDefault(d => d.GetPropertyValue <int>("ArticleId") == _article.ArticleId &&
                                                            d.GetPropertyValue <int>("LanguageId") == i).GetPropertyValue <Guid>("id"),
                            EventType     = ServiceBusEventType.Delete,
                            Discriminator = Constants.ArticlesDiscriminator,
                            PartitionKey  = i.ToString()
                        };
                        await _Eventcontext.PublishThroughEventBusAsync(deleteEvt);
                    }
                    scope.Complete();
                }
                return(response);
            }
            catch (Exception ex)
            {
                response.IsSuccessful  = false;
                response.FailureReason = "Technical Error";
                // _logger.LogError(ex, "Error while handling command");
            }
            return(response);
        }
Esempio n. 25
0
 public ActionResult Delete(int id, Article entity)
 {
     _repo.Delete(id);
     return(RedirectToAction("Index"));
 }
Esempio n. 26
0
        public async Task <ManipulateArticlesCommandResponse> Handle(ManipulateArticlesCommand request, CancellationToken cancellationToken)
        {
            ManipulateArticlesCommandResponse response = new ManipulateArticlesCommandResponse()
            {
                IsSuccessful = false
            };

            Disclaimers     DisclaimersDetails    = new Disclaimers();
            ResourceGroups  ResourceGroupsDetails = new ResourceGroups();
            Provinces       ProvincesDetails      = new Provinces();
            List <TaxTags>  taxTagsDetails        = new List <TaxTags>();
            List <Articles> articlesDetails       = new List <Articles>();
            List <Articles> articles = _ArticleRepository.getArticleCompleteDataById(request.ArticlesIds);

            if (request.ArticlesIds.Count != articles.Count)
            {
                throw new RulesException("Invalid", @"Country not found");
            }
            using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                if (request.Operation == "Publish")
                {
                    foreach (var article in articles)
                    {
                        article.IsPublished = true;
                        _ArticleRepository.Update <Articles>(article);
                    }
                }
                else if (request.Operation == "UnPublish")
                {
                    foreach (var article in articles)
                    {
                        article.IsPublished = false;
                        _ArticleRepository.Update <Articles>(article);
                    }
                }
                else if (request.Operation == "Delete")
                {
                    foreach (Articles article in articles)
                    {
                        foreach (var content in article.ArticleContents.ToList())
                        {
                            article.ArticleContents.Remove(content);
                            _ArticleRepository.Delete <ArticleContents>(content);
                        }
                        foreach (var country in article.ArticleRelatedCountries.ToList())
                        {
                            article.ArticleRelatedCountries.Remove(country);
                        }
                        foreach (var countryGroup in article.ArticleRelatedCountryGroups.ToList())
                        {
                            article.ArticleRelatedCountryGroups.Remove(countryGroup);
                        }
                        foreach (var taxTag in article.ArticleRelatedTaxTags.ToList())
                        {
                            article.ArticleRelatedTaxTags.Remove(taxTag);
                        }
                        foreach (var relatedArticle in article.RelatedArticlesArticle.ToList())
                        {
                            article.RelatedArticlesArticle.Remove(relatedArticle);
                            //Remove reverse relation
                            // relatedArticle.RelatedArticles.Remove(article);
                        }
                        foreach (var relatedResource in article.RelatedResourcesArticle.ToList())
                        {
                            article.RelatedResourcesArticle.Remove(relatedResource);
                        }
                        foreach (var readArticle in article.UserReadArticles.ToList())
                        {
                            article.UserReadArticles.Remove(readArticle);
                            _ArticleRepository.Delete <UserReadArticles>(readArticle);
                        }
                        foreach (var savedArticle in article.UserSavedArticles.ToList())
                        {
                            article.UserSavedArticles.Remove(savedArticle);
                            _ArticleRepository.Delete <UserSavedArticles>(savedArticle);
                        }
                        foreach (var contact in article.ArticleRelatedContacts.ToList())
                        {
                            article.ArticleRelatedContacts.Remove(contact);
                        }
                        _ArticleRepository.DeleteArticle(article);
                    }
                }
                else
                {
                    throw new RulesException("Operation", @"The Operation " + request.Operation + " is not valied");
                }
                await _ArticleRepository.UnitOfWork
                .SaveEntitiesAsync();

                response.IsSuccessful = true;
                scope.Complete();
            }
            var articleDocs = _context.GetAll(Constants.ArticlesDiscriminator);

            if (request.Operation == "Publish" || request.Operation == "UnPublish")
            {
                foreach (var article in articles)
                {
                    taxTagsDetails        = _ArticleRepository.getTaxTagsDetailsByIds(article.ArticleRelatedTaxTags.Select(s => s.TaxTagId).ToList());
                    articlesDetails       = _ArticleRepository.getArticleCompleteDataById(article.RelatedArticlesArticle.Select(s => s.RelatedArticleId).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()));
                    using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                    {
                        foreach (var doc in articleDocs.Where(d => d.GetPropertyValue <int>("ArticleId") == article.ArticleId))
                        {
                            var DisclaimerLanguageId    = DisclaimersDetails.DisclaimerContents.Where(d => d.LanguageId == doc.GetPropertyValue <int>("LanguageId")).Count() > 0 ? doc.GetPropertyValue <int>("LanguageId") : 37;
                            var ResourceGroupLanguageId = ResourceGroupsDetails.ResourceGroupContents.Where(d => d.LanguageId == doc.GetPropertyValue <int>("LanguageId")).Count() > 0 ? doc.GetPropertyValue <int>("LanguageId") : 37;
                            var ProvisionsLanguageId    = ProvincesDetails.ProvinceContents.Where(d => d.LanguageId == doc.GetPropertyValue <int>("LanguageId")).Count() > 0 ? doc.GetPropertyValue <int>("LanguageId") : 37;


                            var eventSourcing = new ArticleCommandEvent()
                            {
                                id = doc != null?doc.GetPropertyValue <Guid>("id") : Guid.NewGuid(),
                                         EventType        = doc != null ? ServiceBusEventType.Update : 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          = request.Operation == "Publish" ? true : false,
                                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      = doc.GetPropertyValue <int>("ArticleContentId") == null ? -1 : doc.GetPropertyValue <int>("ArticleContentId"),
                                LanguageId            = doc.GetPropertyValue <int>("LanguageId") == null ? -1 : doc.GetPropertyValue <int>("LanguageId"),
                                Title                 = doc.GetPropertyValue <string>("Title") == null ? "" : doc.GetPropertyValue <string>("Title"),
                                TitleInEnglishDefault = doc.GetPropertyValue <string>("TitleInEnglishDefault") == null ? "" : doc.GetPropertyValue <string>("TitleInEnglishDefault"),
                                TeaserText            = doc.GetPropertyValue <string>("TeaserText") == null ? "" : doc.GetPropertyValue <string>("TeaserText"),
                                Content               = doc.GetPropertyValue <string>("Content") == null ? "" : doc.GetPropertyValue <string>("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 == doc.GetPropertyValue <int>("LanguageId")).Count() > 0 ? doc.GetPropertyValue <int>("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 == doc.GetPropertyValue <int>("LanguageId")).Count() > 0 ? doc.GetPropertyValue <int>("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().ToString(), 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 == doc.GetPropertyValue <int>("LanguageId")).Count() > 0 ? doc.GetPropertyValue <int>("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().ToString(), 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();
                    }
                }
            }
            else if (request.Operation == "Delete")
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    foreach (var item in articles)
                    {
                        foreach (var content in item.ArticleContents)
                        {
                            foreach (var article in articleDocs.Where(ad => ad.GetPropertyValue <int>("LanguageId") == content.LanguageId))
                            {
                                foreach (var relatedArticles in article.GetPropertyValue <List <RelatedArticlesSchema> >("RelatedArticles"))
                                {
                                    if (relatedArticles.ArticleId == item.ArticleId)
                                    {
                                        List <RelatedArticlesSchema> relatedArticleSchema = new List <RelatedArticlesSchema>();
                                        relatedArticleSchema = article.GetPropertyValue <List <RelatedArticlesSchema> >("RelatedArticles");

                                        var index = relatedArticleSchema.IndexOf(relatedArticleSchema.Where(i => i.ArticleId == item.ArticleId).First());
                                        if (index != -1)
                                        {
                                            relatedArticleSchema.Remove(relatedArticleSchema.Where(i => i.ArticleId == item.ArticleId).First());
                                        }
                                        var eventSourcingRelated = new ArticleCommandEvent()
                                        {
                                            id = article != null?article.GetPropertyValue <Guid>("id") : Guid.NewGuid(),
                                                     EventType             = ServiceBusEventType.Update,
                                                     ArticleId             = article.GetPropertyValue <int>("ArticleId"),
                                                     PublishedDate         = article.GetPropertyValue <string>("PublishedDate"),
                                                     Author                = article.GetPropertyValue <string>("author"),
                                                     ImageId               = article.GetPropertyValue <int>("ImageId"),
                                                     State                 = article.GetPropertyValue <string>("State"),
                                                     Type                  = article.GetPropertyValue <int>("Type"),
                                                     SubType               = article.GetPropertyValue <int>("SubType"),
                                                     ResourcePosition      = article.GetPropertyValue <int>("ResourcePosition"),
                                                     Disclaimer            = article.GetPropertyValue <DisclamersSchema>("Disclaimer"),
                                                     ResourceGroup         = article.GetPropertyValue <ResourceGroupsSchema>("ResourceGroup"),
                                                     IsPublished           = article.GetPropertyValue <bool>("IsPublished"),
                                                     CreatedDate           = article.GetPropertyValue <string>("CreatedDate"),
                                                     CreatedBy             = article.GetPropertyValue <string>("CreatedBy"),
                                                     UpdatedDate           = article.GetPropertyValue <string>("UpdatedDate"),
                                                     UpdatedBy             = article.GetPropertyValue <string>("UpdatedBy"),
                                                     NotificationSentDate  = article.GetPropertyValue <string>("NotificationSentDate"),
                                                     Provinces             = article.GetPropertyValue <ProvinceSchema>("Provisions"),
                                                     ArticleContentId      = article.GetPropertyValue <int>("ArticleContentId"),
                                                     LanguageId            = article.GetPropertyValue <int>("LanguageId"),
                                                     Title                 = article.GetPropertyValue <string>("Title"),
                                                     TitleInEnglishDefault = article.GetPropertyValue <string>("TitleInEnglishDefault"),
                                                     TeaserText            = article.GetPropertyValue <string>("TeaserText"),
                                                     Content               = article.GetPropertyValue <string>("Content"),
                                                     RelatedContacts       = article.GetPropertyValue <List <RelatedEntityId> >("RelatedContacts"),
                                                     RelatedCountries      = article.GetPropertyValue <List <RelatedEntityId> >("RelatedCountries"),
                                                     RelatedCountryGroups  = article.GetPropertyValue <List <RelatedEntityId> >("RelatedCountryGroups"),
                                                     RelatedTaxTags        = article.GetPropertyValue <List <RelatedTaxTagsSchema> >("RelatedTaxTags"),
                                                     RelatedArticles       = relatedArticleSchema,
                                                     RelatedResources      = article.GetPropertyValue <List <RelatedArticlesSchema> >("RelatedResources"),
                                                     Discriminator         = article.GetPropertyValue <string>("Discriminator"),
                                                     PartitionKey          = ""
                                        };
                                        await _Eventcontext.PublishThroughEventBusAsync(eventSourcingRelated);
                                    }
                                }
                            }
                        }
                        foreach (var doc in articleDocs.Where(d => d.GetPropertyValue <int>("ArticleId") == item.ArticleId))
                        {
                            var articleevent = new ArticleCommandEvent()
                            {
                                id            = doc.GetPropertyValue <Guid>("id"),
                                EventType     = ServiceBusEventType.Delete,
                                Discriminator = Constants.ArticlesDiscriminator,
                                PartitionKey  = doc.GetPropertyValue <int>("LanguageId").ToString()
                            };
                            await _Eventcontext.PublishThroughEventBusAsync(articleevent);
                        }
                    }
                    scope.Complete();
                }
            }

            return(response);
        }
 public ActionResult DeleteArticle(int id)
 {
     if (AuthenticationManager.LoggedUser.GetType().BaseType.Equals(typeof(Teacher)))
     {
         Article article = new Article();
         ArticleRepository articleRepository = new ArticleRepository();
         article = articleRepository.GetById(id);
         articleRepository.Delete(article);
         return RedirectToAction("Articles");
     }
     return RedirectToAction("Articles");
 }
Esempio n. 28
0
        public static void Main(string[] args)
        {
            Console.WriteLine("----------- Strategy Pattern ------------");
            var husky = new Husky();

            husky.Bark();
            husky.Run();

            husky.SetBarkBehavior(new BarkElectronical());
            husky.Bark();


            Console.WriteLine("----------- Singleton ------------");
            var bankValues1 = BankValues.GetInstance();
            var bankValues2 = BankValues.GetInstance();

            Console.WriteLine(bankValues1 == bankValues2
                ? "Oh yes, I am the same instance"
                : "Nope, I am another BankValue instance.");

            Console.WriteLine("----------- Factory Method ------------");
            var shop = new SoftwareShop().GetProgram(OfficeProg.Powerpoint);

            Console.WriteLine("----------- Facade ------------");
            var officeTask = new OfficeFacade();

            officeTask.PrintDocument();

            Console.WriteLine("----------- State ------------");
            var lumpi = new Doggy();

            lumpi.Play();
            lumpi.Anger();
            lumpi.GiveMeal();
            lumpi.Stroke();
            lumpi.LeaveAlone();

            Console.WriteLine("----------- DI with Autofac ------------");
            var container = ContainerConfig.Configure();

            using (var scope = container.BeginLifetimeScope())
            {
                var app = scope.Resolve <IApplication>();
                app.Run();
            }

            Console.WriteLine("----------- Repository ------------");
            ArticleRepository artRepo = new ArticleRepository();
            List <Article>    artList = artRepo.ReadAll();

            Console.WriteLine($"Found {artList.Count} articles in the List");
            artRepo.Create(new Article {
            });
            var artLatest = artRepo.ReadLatest();

            Console.WriteLine($"Title: {artLatest.Title}, ID: {artLatest.Id}");
            artList = artRepo.ReadAll();
            Console.WriteLine($"Found {artList.Count} articles in the List");
            artRepo.Update(new Article {
            });
            Console.WriteLine($"FOUND: {artRepo.ReadById(1).Title}");
            artRepo.Delete(new Article {
            });
            artList = artRepo.ReadAll();
            Console.WriteLine($"Found {artList.Count} articles in the List");
        }
Esempio n. 29
0
 public async Task DeleteArticle(long id)
 {
     await _repository.Delete(id);
 }
Esempio n. 30
0
 public Article Delete(int id)
 {
     return(db.Delete(id));
 }
Esempio n. 31
0
 public void Delete(ArticleViewModel articleViewModel)
 {
     _articleRepository.Delete(articleViewModel.Id);
 }