Esempio n. 1
0
        public async Task <VmMap> CreateMapAsync(VmMapCreateForm form, Guid viewId, CancellationToken ct)
        {
            try
            {
                await validateViewAndTeams(form.TeamIds, viewId, ct);
            }
            catch (Exception ex)
            {
                throw new ForbiddenException(ex.Message);
            }

            // Check if the team already has a map.
            var existing = await _context.Maps
                           .ToListAsync(ct);

            if (form.TeamIds != null)
            {
                foreach (var m in existing)
                {
                    foreach (var id in form.TeamIds)
                    {
                        if (m.TeamIds.Contains(id))
                        {
                            throw new ForbiddenException("Cannot assign multiple maps to a single team");
                        }
                    }
                }
            }

            var mapIntermediate = _mapper.Map <VmMap>(form);

            mapIntermediate.ViewId = viewId;

            var mapEntity = _mapper.Map <Domain.Models.VmMap>(mapIntermediate);

            _context.Maps.Add(mapEntity);
            await _context.SaveChangesAsync(ct);

            return(_mapper.Map <VmMap>(mapEntity));
        }
Esempio n. 2
0
        public async Task <IActionResult> CreateMap([FromBody] VmMapCreateForm form, [FromRoute] Guid viewId, CancellationToken ct)
        {
            var createdMap = await _vmService.CreateMapAsync(form, viewId, ct);

            return(CreatedAtAction(nameof(this.GetMap), new { mapId = createdMap.Id }, createdMap));
        }