public async Task <IActionResult> Delete([FromRoute] long id) { await _context.EducationalInstitutions .Where(x => x.Id == id) .DeleteFromQueryAsync() .ConfigureAwait(false); await _context.SaveChangesAsync() .ConfigureAwait(false); var @event = new EducationalInstitutionsChanged { Deleted = new List <long> { id } }; _eventBus.Publish(@event); return(Ok()); }
public async Task <IActionResult> Post([FromBody] DtoEducationalInstitution dto) { var entity = Mapper.Map <EducationalInstitution>(dto); _context.EducationalInstitutions.Add(entity); await _context .SaveChangesAsync() .ConfigureAwait(false); dto.Id = entity.Id; var @event = new EducationalInstitutionsChanged { Created = new List <DtoEducationalInstitution> { dto } }; _eventBus.Publish(@event); return(Ok(entity.Id)); }
private async Task <long> AddUniversity() { var institution = new EducationalInstitution { Name = "Томский Политехнический Университет", SiteUrl = "http://tpu.ru/", Acronym = "НИ ТПУ", Description = "Политех", AreaId = await _context.Areas.Select(x => x.Id).FirstAsync() }; _context.EducationalInstitutions.Add(institution); await _context.SaveChangesAsync(); var @event = new EducationalInstitutionsChanged { Created = new[] { Mapper.Map <DtoEducationalInstitution>(institution) } }; _eventBus.Publish(@event); return(institution.Id); }
public async Task <IActionResult> Update([FromBody] DtoEducationalInstitution dto, [FromRoute] long id) { var template = Mapper.Map <EducationalInstitution>(dto); template.Id = id; await _context.EducationalInstitutions .Where(x => x.Id == id) .UpdateFromQueryAsync(_ => template) .ConfigureAwait(false); dto.Id = id; var @event = new EducationalInstitutionsChanged { Updated = new List <DtoEducationalInstitution> { dto } }; _eventBus.Publish(@event); return(Ok(id)); }