Beispiel #1
0
        public IActionResult CreatePermit([FromBody] PermitInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            return(Ok(_permitAppService.CreatePermit(model).Result));
        }
Beispiel #2
0
        public async Task <ResponseViewModel> CreatePermit(PermitInputModel model)
        {
            var permitType = _permitService.GetPermitTypes().FirstOrDefault(x => x.Id == model.PermitTypeId);

            if (permitType == null)
            {
                return(NotFound(ResponseMessageViewModel.INVALID_PERMIT_TYPE, ResponseErrorCodeStatus.INVALID_PERMIT_TYPE));
            }

            var user = await _userManager.FindByIdAsync(_httpContextAccessor.HttpContext.User.GetLoggedInUserId <int>().ToString());

            var result = _mapper.Map <PermitInputModel, Permit>(model);

            if (model.PermitTypeId == (int)PermitTypeEnum.VISIT)
            {
                result.Visitor.AppUserId = user.Id;

                result.AppUserId = user.Id;
            }
            else
            {
                if (model.Vehicle == null)
                {
                    return(NotFound(ResponseMessageViewModel.INVALID_VEHICLE_DETAILS, ResponseErrorCodeStatus.INVALID_VEHICLE_DETAILS));
                }

                var type = _vehicleRepository.GetVehicleTypes().FirstOrDefault(x => x.Id == model.Vehicle.VehicleTypeId);

                if (type == null)
                {
                    return(NotFound(ResponseMessageViewModel.INVALID_VEHICLE_TYPE, ResponseErrorCodeStatus.INVALID_VEHICLE_TYPE));
                }


                result.Vehicle.AppUserId = user.Id;

                result.AppUserId = user.Id;
            }

            result.PermitStatusId = (int)PermitStatusEnum.PENDING;

            result.QRCodeCodeLink = null;

            var savedResult = _permitService.Create(result);

            var mappedResult = _mapper.Map <Permit, PermitViewModel>(savedResult);

            return(Ok(mappedResult));
        }