コード例 #1
0
        public IActionResult Create([FromBody] CreateGarageModel model)
        {
            var garage  = _mapper.Map <Garage>(model);
            var context = HttpContext.User.Identity;
            int id      = int.Parse(context.Name);

            try
            {
                _garageService.Create(garage, id);
                return(Ok(new { message = "✓ Garage Creation Success" }));
            }
            catch (AppException ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }
コード例 #2
0
        public async Task <IActionResult> Create([FromBody] CreateGarageModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var garage    = Mapper.Map <Garage>(model);
            var newGarage = await _garageService.CreateAsync(garage);

            if (newGarage == null)
            {
                return(BadRequest());
            }

            return(Ok(newGarage));
        }