示例#1
0
        public async Task <Team> UpdateAsync(Guid id, ViewModels.TeamForm form, CancellationToken ct)
        {
            var teamToUpdate = await _context.Teams.SingleOrDefaultAsync(t => t.Id == id, ct);

            if (teamToUpdate == null)
            {
                throw new EntityNotFoundException <Team>();
            }

            if (!(await _authorizationService.AuthorizeAsync(_user, null, new ViewAdminRequirement(teamToUpdate.ViewId))).Succeeded)
            {
                throw new ForbiddenException();
            }

            _mapper.Map(form, teamToUpdate);

            _context.Teams.Update(teamToUpdate);
            await _context.SaveChangesAsync(ct);

            var team = await GetAsync(id, ct);

            return(_mapper.Map <Team>(team));
        }
示例#2
0
        public async Task <Team> CreateAsync(Guid viewId, ViewModels.TeamForm form, CancellationToken ct)
        {
            if (!(await _authorizationService.AuthorizeAsync(_user, null, new ViewAdminRequirement(viewId))).Succeeded)
            {
                throw new ForbiddenException();
            }

            var viewEntity = await _context.Views.SingleOrDefaultAsync(e => e.Id == viewId, ct);

            if (viewEntity == null)
            {
                throw new EntityNotFoundException <View>();
            }

            var teamEntity = _mapper.Map <TeamEntity>(form);

            viewEntity.Teams.Add(teamEntity);
            await _context.SaveChangesAsync(ct);

            var team = await GetAsync(teamEntity.Id, ct);

            return(_mapper.Map <Team>(team));
        }