Esempio n. 1
0
        public async Task <Response <SpaceResponse> > CreateAsync(Space space)
        {
            var spaceType = await spaceTypeRepository.GetAsync(space.SpaceTypeGuid);

            if (spaceType == null)
            {
                return(new Response <SpaceResponse>(
                           HttpStatusCode.NotFound,
                           $"SpaceType with guid '{space.SpaceTypeGuid}' was not found."));
            }
            var dbSpace = automapper.Map <DbSpace>(space);

            dbSpace.MapFile = automapper.Map <DbMapFile>(space.Map);
            dbSpace.TypeId  = spaceType.TypeId;
            var result = await spaceRepository.CreateAsync(dbSpace);

            return(new Response <SpaceResponse>(automapper.Map <SpaceResponse>(result)));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([FromBody] Space space)
        {
            if (space == null)
            {
                return(BadRequest()); // 400 Bad request
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState)); // 400 Bad request
            }

            Space added = await repo.CreateAsync(space);

            return(CreatedAtRoute( // 201 Created
                       routeName: nameof(GetSpace),
                       routeValues: new { id = added.SpaceId.ToString().ToLower() },
                       value: added));
        }