コード例 #1
0
        public async Task <IActionResult> Create(GarageViewModel model)
        {
            try
            {
                var result = await _garageService.Create(model);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                ex.ToExceptionless().Submit();
                return(BadRequest());
            }
        }
コード例 #2
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 }));
            }
        }
コード例 #3
0
        public async Task <IHttpActionResult> CreateGarage()
        {
            ResponseDataDTO <int> response = new ResponseDataDTO <int>();

            try
            {
                var path = Path.GetTempPath();
                MultipartFormDataStreamProvider streamProvider = new MultipartFormDataStreamProvider(path);
                // get data from formdata
                GarageViewModel GarageViewModel = new GarageViewModel
                {
                    GarageID   = Guid.Parse(streamProvider.FormData["GarageID"]),
                    GarageName = Convert.ToString(streamProvider.FormData["GarageName"]),
                    Address    = Convert.ToString(streamProvider.FormData["Address"]),
                    DateStart  = Convert.ToDateTime(streamProvider.FormData["DateStart"]),
                    DateEnd    = Convert.ToDateTime(streamProvider.FormData["DateEnd"]),
                };
                // mapping view model to entity
                var createdGarage = _mapper.Map <Garage>(GarageViewModel);
                // save new Garage
                _Garageservice.Create(createdGarage);
                // return response
                response.Code    = HttpCode.OK;
                response.Message = MessageResponse.SUCCESS;
                response.Data    = 1;
                return(Ok(response));
            }
            catch (Exception ex)
            {
                response.Code    = HttpCode.INTERNAL_SERVER_ERROR;
                response.Message = MessageResponse.FAIL;
                response.Data    = 0;
                Console.WriteLine(ex.ToString());

                return(Ok(response));
            }
        }