public IActionResult AddVehicle([FromBody] VehicleViewModel model)
        {
            var response = ServerResponse.OK;

            if (string.IsNullOrEmpty(model.Token))
            {
                return(Ok(_errorMapper.MapToError(ServerResponse.BadRequest, Resource.EmptyToken)));
            }
            model.UserId = Convert.ToInt32(_requestValidator.GetUserFromToken(model.Token));
            response     = _requestValidator.ValidateVehicle(model);
            if (response.RespCode != 200)
            {
                return(Ok(response));
            }
            if (model.VehicleId == 0)
            {
                bool exist = _requestValidator.DeviceExists(model.Device.ImeiNumber);
                if (exist)
                {
                    return(Ok(_errorMapper.MapToError(ServerResponse.BadRequest, string.Format(Resource.AlreadyExist, "Device"))));
                }
            }
            else
            {
                if (!_requestValidator.IsPermittedToEditVehicle(model.UserId.ToString(), model.VehicleId))
                {
                    return(Ok(_errorMapper.MapToError(ServerResponse.BadRequest, Resource.NotPermittedToEditVehicle)));
                }
            }
            response = _vehicleManagement.AddVehicle(model);
            return(Ok(response));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] DataObjects.Domain.File model)
        {
            var response = ServerResponse.OK;

            if (string.IsNullOrEmpty(model.Source))
            {
                return(Ok(_errorMapper.MapToError(ServerResponse.BadRequest, Resource.EmptySourceUrl)));
            }

            string protocol = _fileManager.GetProtocolFromSource(model.Source);

            if (string.IsNullOrEmpty(protocol))
            {
                return(Ok(_errorMapper.MapToError(ServerResponse.BadRequest, Resource.InvalidProtocol)));
            }

            var isValidSourceUrl = RequestValidator.CheckURLValid(model.Source, protocol);

            if (!isValidSourceUrl)
            {
                return(Ok(_errorMapper.MapToError(ServerResponse.BadRequest, Resource.InvalidSourceUrl)));
            }

            switch (protocol)
            {
            case Protocol.Http:
                response = await _fileDownloader.DownloadDataFromHttpToLocalDisk(model.Source, protocol);

                break;

            case Protocol.Https:
                response = await _fileDownloader.DownloadDataFromHttpsToLocalDisk(model.Source, protocol);

                break;

            case Protocol.ftp:
                response = await _fileDownloader.DownloadDataFromFtpToLocalDisk(model.Source, protocol);

                break;

            case Protocol.sftp:
                response = await _fileDownloader.DownloadDataFromSftpToLocalDisk(model.Source, protocol);

                break;

            case Protocol.tcp:
                response = await _fileDownloader.DownloadDataFromTcpToLocalDisk(model.Source, protocol);

                break;

            case Protocol.pipe:
                response = await _fileDownloader.DownloadDataFromPipeToLocalDisk(model.Source, protocol);

                break;
            }
            return(Ok(response));
        }
        public async Task <IActionResult> Post([FromBody] ApplicantModel request)
        {
            _logger.LogInformation("POST for creating Applicant with request: " + JsonConvert.SerializeObject(request));
            var validationResult = _validationManager.Validate(new ApplicantModelValidator(), request);

            if (validationResult.Errors.Count > 0)
            {
                return(Ok(_errorMapper.MapToError(ServerResponse.BadRequest, validationResult.Errors)));
            }
            var response = await _applicantManager.CreateApplicantAsync(request);

            _logger.LogInformation("POST for creating Applicant with response: " + JsonConvert.SerializeObject(response));
            return(Ok(response));
        }
        public async Task <ServerResponse> CreateApplicantAsync(ApplicantModel model)
        {
            var response = ServerResponse.OK;

            _logger.LogInformation("Get Item by ID: " + model.ID);
            var applicant = await _applicantRepository.GetItemByIdAsync(model.ID);

            if (applicant != null)
            {
                _logger.LogInformation("Already exists in system.");
                return(_errorMapper.MapToError(ServerResponse.BadRequest, "Already exists in system."));
            }

            await _applicantRepository.AddAsync(model.ToCommand());

            _logger.LogInformation("Applicant is added by applicant repository.");
            return(response);
        }
Ejemplo n.º 5
0
        public UserViewModel Authenticate(string username, string password)
        {
            var response = ServerResponse.OK;
            var result   = _userRepository.Get().SingleOrDefault(x => x.UserName == username);

            if (result == null)
            {
                return(_errorMapper.MapToError(null, ServerResponse.BadRequest, "User is not found."));
            }
            bool isValid = _cryptographyHandler.VerifyGeneratedHash(password, result.Password);

            if (!isValid)
            {
                return(_errorMapper.MapToError(null, ServerResponse.BadRequest, "Username or password is incorrect."));
            }
            var user = _mapper.Map <UserViewModel>(result);

            user.Token    = _jwtTokenHandler.GenerateJwtSecurityToken(user.UserId.ToString());
            user.Password = null;
            return(user);
        }
        public IActionResult RecordLocation([FromBody] LocationViewModel model)
        {
            var response = ServerResponse.OK;

            if (string.IsNullOrEmpty(model.Token))
            {
                return(Ok(_errorMapper.MapToError(ServerResponse.BadRequest, Resource.EmptyToken)));
            }
            if (!_requestValidator.IsValidToken(model.Token))
            {
                return(Ok(_errorMapper.MapToError(ServerResponse.BadRequest, Resource.InvalidToken)));
            }
            response = _requestValidator.ValidateLocation(model);
            if (response.RespCode != 200)
            {
                return(Ok(response));
            }
            if (!_requestValidator.VehicleExists(model.VehicleId))
            {
                return(Ok(_errorMapper.MapToError(ServerResponse.BadRequest, string.Format(Resource.NotFound, "Vehicle"))));
            }
            var userId = _requestValidator.GetUserFromToken(model.Token);

            if (!_requestValidator.IsPermittedToAddLocation(userId, model.VehicleId))
            {
                return(Ok(_errorMapper.MapToError(ServerResponse.BadRequest, Resource.NotPermittedToAddPosition)));
            }
            response = _locationManagement.RecordLocation(model);
            return(Ok(response));
        }
Ejemplo n.º 7
0
        public IActionResult Register([FromBody] UserViewModel model)
        {
            var response = ServerResponse.OK;

            response = _requestValidator.ValidateUser(model);
            if (response.RespCode != 200)
            {
                return(Ok(response));
            }
            if (model.UserId == 0)
            {
                bool exist = _requestValidator.UserExists(model.UserName);
                if (exist)
                {
                    return(Ok(_errorMapper.MapToError(ServerResponse.BadRequest, string.Format(Resource.AlreadyExist, "User"))));
                }
            }
            response = _userManagement.AddUser(model);
            return(Ok(response));
        }