public async Task <Unit> Handle(DeleteCommentViewModel request, CancellationToken cancellationToken) { var Comment = await covidDbContext.Comments.FindAsync(request.Id); if (Comment != null) { covidDbContext.Comments.Remove(Comment); await covidDbContext.SaveChanges(cancellationToken); } return(Unit.Value); }
public async Task <Unit> Handle(DeleteArticleViewModel request, CancellationToken cancellationToken) { var Article = await covidDbContext.Articles.FindAsync(request.Id); if (Article != null) { covidDbContext.Articles.Remove(Article); await covidDbContext.SaveChanges(cancellationToken); } return(Unit.Value); }
public async Task <Unit> Handle(UpdateRepublicViewModel request, CancellationToken cancellationToken) { var Republic = covidDbContext.Republics.Find(request.Title); if (Republic != null) { covidDbContext.Republics.Update(Republic); await covidDbContext.SaveChanges(cancellationToken); } return(Unit.Value); }
public async Task <Unit> Handle(AddRepublicViewModel request, CancellationToken cancellationToken) { var Republic = new Republic() { Title = request.Title, Population = request.Population, Square = request.Square }; if (Republic != null) { await covidDbContext.Republics.AddAsync(Republic); await covidDbContext.SaveChanges(cancellationToken); } return(Unit.Value); }
public async Task <Unit> Handle(CreateArticleViewModel request, CancellationToken cancellationToken) { var User = await userManager.FindByIdAsync(request.AppUserId); if (User != null) { var Article = new Article() { AppUserId = User.Id, Content = request.Content, Tags = request.Tags, Title = request.Title }; covidDbContext.Articles.Add(Article); await covidDbContext.SaveChanges(cancellationToken); } return(Unit.Value); }
public async Task <Unit> Handle(AddCommentViewModel request, CancellationToken cancellationToken) { var UserFrom = await userManager.FindByEmailAsync(request.FromUserEmail); var UserTo = await covidDbContext.Articles.FindAsync(request.ToId); if ((UserFrom != null) && (UserTo != null)) { var Comment = new Comment() { FromId = UserFrom.Id, From = UserFrom, ArticleToId = UserTo.Id, ArticleTo = UserTo, Message = request.Message }; covidDbContext.Comments.Add(Comment); await covidDbContext.SaveChanges(cancellationToken); } return(Unit.Value); }
public async Task <Unit> Handle(UpdateStatisticViewModel request, CancellationToken cancellationToken) { var Republic = await covidDbContext.Republics.FindAsync(request.Republic); var Virus = await covidDbContext.Viruses.FindAsync(request.Virus); if ((Republic != null) && (Virus != null)) { var Stat = new Statistic() { CountInfected = request.CountInfected, Dead = request.Dead, Recovered = request.Recovered, Republic = Republic, Virus = Virus, }; covidDbContext.Statistics.Update(Stat); await covidDbContext.SaveChanges(cancellationToken); } return(Unit.Value); }
public async Task <RepublicsViewModel> Handle(GetRepublicsListQuery request, CancellationToken cancellationToken) { if (!context_.Republics.Any()) { HtmlLoader_ = new HtmlLoader <Republic>(this.settings_); var source_ = await HtmlLoader_.GetSourceByPageId(); CQ cq = CQ.Create(source_); var result = parser_.Parse(cq).ToArray(); for (int i = 0; i < result.Count(); i++) { context_.Republics.Add(result[i]); await context_.SaveChanges(cancellationToken); } return(new RepublicsViewModel() { Republics = result.Select(x => new RepublicDto() { Population = x.Population, Square = x.Square, Title = x.Title }).ToList() }); } else { var republics = await context_.Republics.ToListAsync(cancellationToken); return(new RepublicsViewModel() { Republics = republics.Select(x => new RepublicDto() { Population = x.Population, Square = x.Square, Title = x.Title }).ToList() }); } }