コード例 #1
0
        public async Task <IActionResult> AddWall([FromBody] WallForAddDto wallForAddDto)
        {
            try
            {
                if (wallForAddDto == null) // didn't get anything from request body
                {
                    //_logger.LogError("Invalid wall object sent from client request");
                    return(BadRequest("Wall object is null"));
                }

                if (!ModelState.IsValid) // check to see if request was bound correctly
                {
                    //_logger.LogError("Invalid retaining wall object sent from client request.");
                    return(BadRequest("Invalid retaining wall object."));
                }

                // create RetainingWall object by mapping from AutoMapper
                var retainingWall = _mapper.Map <RetainingWall>(wallForAddDto);

                // make repo call to add user
                var addedWall = await _repo.AddWall(retainingWall);

                // this is for returning the newly created wall ID in the database to the client
                var addedWallToReturn = _mapper.Map <WallForAddDto>(addedWall);

                return(Ok(addedWallToReturn.Id));
            }
            catch (Exception ex)
            {
                //_logger.LogError(ex.Message);
                return(StatusCode(500, "Internal server error"));
            }
        }
コード例 #2
0
        public WallViewModel CreateWall(WallUpdateModel wall)
        {
            var theWall = new Wall();

            theWall.X               = wall.X;
            theWall.Y               = wall.Y;
            theWall.Length          = wall.Length;
            theWall.Angle           = wall.Angle;
            theWall.Type            = wall.Type;
            theWall.CreatedDateTime = DateTime.UtcNow;
            theWall.UpdatedDateTime = DateTime.UtcNow;
            return(new WallViewModel(_wallRepository.AddWall(theWall, wall.SiteId)));
        }