Пример #1
0
        public async Task <VmMap> UpdateMapAsync(VmMapUpdateForm form, Guid mapId, CancellationToken ct)
        {
            var vmMapEntity = await _context.Maps
                              .Where(m => m.Id == mapId)
                              .Include(m => m.Coordinates)
                              .SingleOrDefaultAsync(ct);

            if (vmMapEntity == null)
            {
                throw new EntityNotFoundException <VmMap>();
            }

            try
            {
                await validateViewAndTeams(form.TeamIds, vmMapEntity.ViewId, ct);
            }
            catch (Exception ex)
            {
                throw new ForbiddenException(ex.Message);
            }

            vmMapEntity.Coordinates.Clear();
            foreach (var coord in form.Coordinates)
            {
                var tempCoord = _mapper.Map <Domain.Models.Coordinate>(coord);
                tempCoord.Id = Guid.Empty;

                vmMapEntity.Coordinates.Add(tempCoord);
            }

            vmMapEntity = _mapper.Map(form, vmMapEntity);

            await _context.SaveChangesAsync(ct);

            return(_mapper.Map <VmMap>(vmMapEntity));
        }
Пример #2
0
        public async Task <IActionResult> UpdateMap([FromBody] VmMapUpdateForm form, [FromRoute] Guid mapId, CancellationToken ct)
        {
            var updated = await _vmService.UpdateMapAsync(form, mapId, ct);

            return(Ok(updated));
        }