コード例 #1
0
        public async Task <IActionResult> CreateMap([FromBody] CreateMapRequestDto createMapRequest)
        {
            if (createMapRequest == null || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Map map;

            try
            {
                map = ToMap(createMapRequest);
            }
            catch (Exception e)
            {
                return(BadRequest($"Map is invalid. {e.Message}"));
            }

            var result = await _mapRepository.Create(map);

            if (result == null)
            {
                return(StatusCode((int)HttpStatusCode.Conflict, "Map with this ID already exists"));
            }

            return(Created(Url.Action("GetMap", new { id = createMapRequest.Id }), null));
        }
コード例 #2
0
        public Map CreateMap(Map map)
        {
            map.CreateDate = DateTime.Now;
            int id = _mapRepository.Create(map);

            return(_mapRepository.GetById(id));
        }
コード例 #3
0
ファイル: MapService.cs プロジェクト: NHadi/Exercises
        public async Task <EntityValidationResult <Map> > AddMap(Map map)
        {
            try
            {
                var result           = new EntityValidationResult <Map>();
                var validationResult = _validator.Validate(map);

                result.IsValid = validationResult.IsValid;
                result.Object  = map;

                if (validationResult.IsValid)
                {
                    map.Id = Guid.NewGuid();

                    _mapRepository.Create(map);
                    await _mapRepository.SaveAsync();
                }
                else
                {
                    result.Errors = validationResult.Errors.Select(x => new EntityValidationFailure {
                        PropertyName = x.PropertyName, ErrorMessage = x.ErrorMessage
                    }).ToList();
                }

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #4
0
        public async Task <bool> Handle(MapEventUseCaseRequest message, IOutputPort <MapEventUseCaseResponse> outputPort)
        {
            var startCoordinate = await _coordinateRepository.Create(message.StartCoordinate);

            var endCoordinate = await _coordinateRepository.Create(message.EndCoordinate);

            await _mapRepository.Create(startCoordinate.coordinate, endCoordinate.coordinate);

            outputPort.Handle(new MapEventUseCaseResponse(null, true, "Map Event Create Complete"));
            return(true);
        }
コード例 #5
0
ファイル: MapService.cs プロジェクト: moayyaed/riverside-cms
 public void Create(IElementSettings settings, IUnitOfWork unitOfWork = null)
 {
     _mapRepository.Create((MapSettings)settings, unitOfWork);
 }