Exemple #1
0
        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());
        }
Exemple #2
0
        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));
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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));
        }