Example #1
0
        public async Task <bool> Authenticate(int companyId, string username, string password, bool setToClose)
        {
            if (ApiUrl != null && ApiUrl.IsValid() && (Token == null || !Token.IsValid()))
            {
                try
                {
                    Token = await ApiUrl.AppendPathSegment("token")
                            .PostUrlEncodedAsync(
                        new
                    {
                        companyId,
                        username,
                        password,
                        setToClose,
                        grant_type = "password"
                    }
                        )
                            .ReceiveJson <ApiTokenModel>();

                    Token.EmployeeViewInfo = await ApiUrl.AppendPathSegment("ws/me")
                                             .GetJsonAsync <EmployeeViewInfoModel>();

                    CompanyId  = companyId;
                    Username   = username;
                    Password   = password;
                    SetToClose = setToClose;

                    return(true);
                }
                catch (FlurlHttpException) { }
                catch (Exception) { }
            }

            return(false);
        }
Example #2
0
        public async Task <string> GetWebServiceVersion()
        {
            try
            {
                return(await ApiUrl.AppendPathSegment("ws/web-service-version")
                       .GetStringAsync());
            }
            catch (FlurlHttpException) { }
            catch (Exception) { }

            return(String.Empty);
        }
Example #3
0
        public async Task <string> CheckVersion()
        {
            try
            {
                return(await ApiUrl.AppendPathSegment("ws/check-version")
                       .GetStringAsync());
            }
            catch (FlurlHttpException) { }
            catch (Exception) { }

            return(String.Empty);
        }
Example #4
0
        public async Task FinalizeSession()
        {
            if (Token?.AccessToken != null)
            {
                await ApiUrl.AppendPathSegment("ws/finalize-session")
                .WithOAuthBearerToken(Token.AccessToken)
                .GetAsync();

                Token     = null;
                CompanyId = 0;
                Username  = String.Empty;
                Password  = String.Empty;
            }
        }
        public async Task <HttpResponseMessage> ReleaseWarehousePassword(string password)
        {
            try
            {
                return(await ApiUrl.AppendPathSegment($"{Controller}/release-warehouse-password/{password}")
                       .PostJsonAsync(EmployeeViewInfo));
            }
            catch (FlurlHttpException e)
            {
                return(new HttpResponseMessage(e.Call.HttpStatus ?? HttpStatusCode.BadRequest));
            }
            catch (Exception) { }

            return(new HttpResponseMessage(HttpStatusCode.BadRequest));
        }
Example #6
0
        protected async Task <HttpRequestResult <TResponse> > GetAsyncAnonimouslyData <TResponse>(string pathSegment)
        {
            try
            {
                return(await ApiUrl.AppendPathSegment(pathSegment)
                       .GetAsync()
                       .HttpRequestResult <TResponse>());
            }
            catch (FlurlHttpException e)
            {
                return(new HttpRequestResult <TResponse>(e.Call.HttpStatus ?? HttpStatusCode.BadRequest));
            }
            catch (Exception) { }

            return(new HttpRequestResult <TResponse>(HttpStatusCode.BadRequest));
        }
        public async Task <HttpRequestResult <VehicleViewInfoModel> > ValidVehicle(string carNumber)
        {
            try
            {
                return(await ApiUrl.AppendPathSegment($"{Controller}/valid-vehicle/{carNumber}")
                       .PostJsonAsync(EmployeeViewInfo)
                       .HttpRequestResult <VehicleViewInfoModel>());
            }
            catch (FlurlHttpException e)
            {
                return(new HttpRequestResult <VehicleViewInfoModel>(e.Call.HttpStatus ?? HttpStatusCode.BadRequest));
            }
            catch (Exception) { }

            return(new HttpRequestResult <VehicleViewInfoModel>(HttpStatusCode.BadRequest));
        }
        public async Task <HttpRequestResult <TeamViewInfoModel> > ValidTeam(int unitId, string teamCode)
        {
            try
            {
                return(await ApiUrl.AppendPathSegment($"{Controller}/valid-team/{unitId}/{teamCode}")
                       .PostJsonAsync(EmployeeViewInfo)
                       .HttpRequestResult <TeamViewInfoModel>());
            }
            catch (FlurlHttpException e)
            {
                return(new HttpRequestResult <TeamViewInfoModel>(e.Call.HttpStatus ?? HttpStatusCode.BadRequest));
            }
            catch (Exception) { }

            return(new HttpRequestResult <TeamViewInfoModel>(HttpStatusCode.BadRequest));
        }
        public async Task <HttpRequestResult <UnitViewInfoModel> > ValidUnit(string unitCode)
        {
            try
            {
                return(await ApiUrl.AppendPathSegment($"{Controller}/valid-unit/{unitCode}")
                       .GetAsync()
                       .HttpRequestResult <UnitViewInfoModel>());
            }
            catch (FlurlHttpException e)
            {
                return(new HttpRequestResult <UnitViewInfoModel>(e.Call.HttpStatus ?? HttpStatusCode.BadRequest));
            }
            catch (Exception) { }

            return(new HttpRequestResult <UnitViewInfoModel>(HttpStatusCode.BadRequest));
        }
        public async Task <HttpRequestResult <PackingListDetailViewInfoModel> > GetWarehousePasswordId(string password)
        {
            try
            {
                return(await ApiUrl.AppendPathSegment($"{Controller}/warehouse-password-id/{password}")
                       .PostJsonAsync(EmployeeViewInfo)
                       .HttpRequestResult <PackingListDetailViewInfoModel>());
            }
            catch (FlurlHttpException e)
            {
                return(new HttpRequestResult <PackingListDetailViewInfoModel>(e.Call.HttpStatus ?? HttpStatusCode.BadRequest));
            }
            catch (Exception) { }

            return(new HttpRequestResult <PackingListDetailViewInfoModel>(HttpStatusCode.BadRequest));
        }
        public async Task <HttpRequestResult <IEnumerable <VehicleViewInfoModel> > > GetTrafficScheduleByCarNumber(string unitLocalCode, string carNumber)
        {
            try
            {
                return(await ApiUrl.AppendPathSegment($"{Controller}/traffic-schedule-by-car-number/{unitLocalCode}/{carNumber}")
                       .PostJsonAsync(EmployeeViewInfo)
                       .HttpRequestResult <IEnumerable <VehicleViewInfoModel> >());
            }
            catch (FlurlHttpException e)
            {
                return(new HttpRequestResult <IEnumerable <VehicleViewInfoModel> >(e.Call.HttpStatus ?? HttpStatusCode.BadRequest));
            }
            catch (Exception) { }

            return(new HttpRequestResult <IEnumerable <VehicleViewInfoModel> >(HttpStatusCode.BadRequest));
        }
Example #12
0
        protected async Task <HttpResponseMessage> DeleteAsync(string pathSegment)
        {
            try
            {
                return(await ApiUrl.AppendPathSegment(pathSegment)
                       .WithOAuthBearerToken(Token.AccessToken)
                       .DeleteAsync());
            }
            catch (FlurlHttpException e)
            {
                return(new HttpResponseMessage(e.Call.HttpStatus ?? HttpStatusCode.BadRequest));
            }
            catch (Exception) { }

            return(new HttpResponseMessage(HttpStatusCode.BadRequest));
        }
Example #13
0
        protected async Task <HttpRequestResult <TResponse> > PutAsyncReceiveData <TResponse, TPut>(string pathSegment, TPut data)
        {
            try
            {
                return(await ApiUrl.AppendPathSegment(pathSegment)
                       .WithOAuthBearerToken(Token.AccessToken)
                       .PutJsonAsync(data)
                       .HttpRequestResult <TResponse>());
            }
            catch (FlurlHttpException e)
            {
                return(new HttpRequestResult <TResponse>(e.Call.HttpStatus ?? HttpStatusCode.BadRequest));
            }
            catch (Exception) { }

            return(new HttpRequestResult <TResponse>(HttpStatusCode.BadRequest));
        }
Example #14
0
        protected async Task <HttpRequestResult <TResponse> > GetAsyncAuthenticatedData <TResponse>(string pathSegment)
        {
            try
            {
                return(await ApiUrl.AppendPathSegment(pathSegment)
                       .WithOAuthBearerToken(Token.AccessToken)
                       .GetAsync()
                       .HttpRequestResult <TResponse>());
            }
            catch (FlurlHttpException e)
            {
                return(new HttpRequestResult <TResponse>(e.Call.HttpStatus ?? HttpStatusCode.BadRequest));
            }
            catch (Exception) { }

            return(new HttpRequestResult <TResponse>(HttpStatusCode.BadRequest));
        }
        public async Task <HttpRequestResult <IEnumerable <VehicleViewInfoModel> > > GetVehiclesInOperationalControl(GetVehiclesInOperationalControlModel model)
        {
            model.AuthenticateInfo = EmployeeViewInfo;
            try
            {
                return(await ApiUrl.AppendPathSegment($"{Controller}/vehicles-in-operational-control")
                       .PostJsonAsync(model)
                       .HttpRequestResult <IEnumerable <VehicleViewInfoModel> >());
            }
            catch (FlurlHttpException e)
            {
                return(new HttpRequestResult <IEnumerable <VehicleViewInfoModel> >(e.Call.HttpStatus ?? HttpStatusCode.BadRequest));
            }
            catch (Exception) { }

            return(new HttpRequestResult <IEnumerable <VehicleViewInfoModel> >(HttpStatusCode.BadRequest));
        }
Example #16
0
        public async Task <AuthenticationResponseModel> Authenticate(int companyId, string username, string password)
        {
            if (ApiUrl != null && ApiUrl.IsValid())
            {
                try
                {
                    var result = await ApiUrl.AppendPathSegment("token")
                                 .AllowAnyHttpStatus()
                                 .PostUrlEncodedAsync(
                        new
                    {
                        companyId,
                        username,
                        password,
                        grant_type = "password"
                    }
                        )
                                 .HttpRequestResult <ApiTokenModel>();

                    if (result.IsSuccessStatusCode && result.Response != null)
                    {
                        Token = result.Response;

                        Token.EmployeeViewInfo = await ApiUrl.AppendPathSegment("ws/me")
                                                 .WithOAuthBearerToken(Token.AccessToken)
                                                 .GetJsonAsync <EmployeeViewInfoModel>();

                        CompanyId = companyId;
                        Username  = username;
                        Password  = password;

                        return(new AuthenticationResponseModel(true));
                    }
                    else
                    {
                        return(new AuthenticationResponseModel(false, result.Error?.ErrorDescription));
                    }
                }
                catch (FlurlHttpException) { }
                catch (Exception) { }
            }

            return(new AuthenticationResponseModel(false));
        }
Example #17
0
        private async Task Authenticate()
        {
            if (ApiUrl != null && ApiUrl.IsValid() &&
                (Token == null || !Token.IsValid()) &&
                !string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password))
            {
                Token = await ApiUrl.AppendPathSegment("token")
                        .PostUrlEncodedAsync(
                    new
                {
                    CompanyId,
                    Username,
                    Password,
                    grant_type = "password"
                }
                    )
                        .ReceiveJson <ApiTokenModel>();

                Token.EmployeeViewInfo = await ApiUrl.AppendPathSegment("ws/me")
                                         .WithOAuthBearerToken(Token.AccessToken)
                                         .GetJsonAsync <EmployeeViewInfoModel>();
            }
        }