Example #1
0
        async public System.Threading.Tasks.Task <CDUserInfo> ValidateUser(string userId, string password)
        {
            try
            {
                var result = await _client.validateUserAsync(userId, password);

                if (result != null && result.response != null)
                {
                    var userInfo = new CDUserInfo
                    {
                        UserId      = result.response.parmUserID,
                        CompanyId   = result.response.parmCompany,
                        CompanyName = result.response.parmCompanyName,
                        Name        = result.response.parmUserName,
                        CDUserType  = (CDUserType)Enum.Parse(typeof(CDUserType), result.response.parmLoginType.ToString()),
                    };

                    this._userInfo = userInfo;
                    return(userInfo);
                }
                return(null);
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #2
0
        //async public System.Threading.Tasks.Task InsertDocumentCollectedByDriverOrCourierToSvcAsync()
        //{
        //    try
        //    {
        //        var connectionProfile = NetworkInformation.GetInternetConnectionProfile();
        //        if (connectionProfile == null || connectionProfile.GetNetworkConnectivityLevel() != NetworkConnectivityLevel.InternetAccess || _userInfo.CDUserType == CDUserType.Customer)
        //            return;

        //        if (_userInfo == null)
        //        {
        //            _userInfo = PersistentData.Instance.UserInfo;
        //        }
        //        var cdDataList = (await SqliteHelper.Storage.LoadTableAsync<DocumentCollectDetail>());
        //        ObservableCollection<MZKCourierCollectionDetailsContract> mzkDocumentCollectedDetailsContractColl = new ObservableCollection<MZKCourierCollectionDetailsContract>();

        //            foreach (var doc in cdDataList)
        //            {
        //                mzkDocumentCollectedDetailsContractColl.Add(new MZKCourierCollectionDetailsContract()
        //                {
        //                    parmCaseId = doc.CaseNumber,
        //                    parmCollectedFrom = doc.SelectedCollectedFrom,
        //                    parmComment = doc.Comment,
        //                    parmEmail = doc.Email,
        //                    parmCaseServiceRecId = doc.CaseServiceRecId,
        //                    parmContactPerson = doc.ReceivedBy,
        //                    parmCollectedBy = doc.ReceivedBy,
        //                    parmPosition = doc.Position,
        //                    parmTelePhone = doc.Phone,
        //                    // parmContactNumber
        //                    // parmCourierSignature = doc.CRSignature.,
        //                    parmReceivedBy = doc.ReceivedBy,
        //                    parmDateTime = doc.ReceivedDate,
        //                    parmContactNumber = doc.Phone

        //                });
        //            }
        //            if (mzkDocumentCollectedDetailsContractColl.Count>0)
        //            {

        //                var res = await _client.insertDocumentDriverCourierDetailsAsync(mzkDocumentCollectedDetailsContractColl, _userInfo.CompanyId);
        //                if (res != null && res.response.Any())
        //                {
        //                    foreach (var cdData in cdDataList)
        //                    {
        //                        if (res.response.Any(a => a.parmCaseId == cdData.CaseNumber && a.parmCaseServiceRecId == cdData.CaseServiceRecId))
        //                        {
        //                            await SqliteHelper.Storage.DeleteSingleRecordAsync<DocumentCollectDetail>(cdData);
        //                        }
        //                    }
        //                }
        //            }

        //    }
        //    catch (Exception ex)
        //    {
        //        this.SendMessageToUIThread(ex.Message);
        //    }
        //}
        async public System.Threading.Tasks.Task InsertDocumentDeliveredByDriverOrCourierToSvcAsync()
        {
            try
            {
                var connectionProfile = NetworkInformation.GetInternetConnectionProfile();
                if (connectionProfile == null || connectionProfile.GetNetworkConnectivityLevel() != NetworkConnectivityLevel.InternetAccess)
                {
                    return;
                }

                if (_userInfo == null)
                {
                    _userInfo = JsonConvert.DeserializeObject <CDUserInfo>(ApplicationData.Current.RoamingSettings.Values[Constants.UserInfo].ToString());
                }
                var cdDataList = (await SqliteHelper.Storage.LoadTableAsync <DocumnetDeliverDetail>());
                ObservableCollection <MZKCourierCollectionDetailsContract> mzkDocumentCollectedDetailsContractColl = new ObservableCollection <MZKCourierCollectionDetailsContract>();

                foreach (var doc in cdDataList)
                {
                    mzkDocumentCollectedDetailsContractColl.Add(new MZKCourierCollectionDetailsContract()
                    {
                        parmCaseId           = doc.CaseNumber,
                        parmCollectedFrom    = doc.SelectedCollectedFrom,
                        parmComment          = doc.Comment,
                        parmEmail            = doc.Email,
                        parmCaseServiceRecId = doc.CaseServiceRecId,
                        parmContactPerson    = doc.DeliveryPersonName,
                        parmCollectedBy      = doc.DeliveryPersonName,
                        parmPosition         = doc.Position,
                        parmTelePhone        = doc.Phone,
                        // parmContactNumber
                        // parmCourierSignature = doc.CRSignature.,
                        parmReceivedBy    = doc.DeliveryPersonName,
                        parmDateTime      = doc.DeliveryDate,
                        parmContactNumber = doc.Phone
                    });
                }
                if (mzkDocumentCollectedDetailsContractColl.Count > 0)
                {
                    var res = await _client.insertDocumentDriverCourierDetailsAsync(mzkDocumentCollectedDetailsContractColl, _userInfo.CompanyId);

                    if (res != null && res.response.Any())
                    {
                        foreach (var cdData in cdDataList)
                        {
                            if (res.response.Any(a => a.parmCaseId == cdData.CaseNumber && a.parmCaseServiceRecId == cdData.CaseServiceRecId))
                            {
                                await SqliteHelper.Storage.DeleteSingleRecordAsync <DocumnetDeliverDetail>(cdData);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.SendMessageToUIThread(ex.Message);
            }
        }
Example #3
0
        private void RaiseUserChanged(CDUserInfo newUserInfo, CDUserInfo oldUserInfo)
        {
            var handler = UserChanged;

            if (handler != null)
            {
                handler(this, new BusinessLogic.EventArgs.UserChangedEventArgs(newUserInfo, oldUserInfo));
            }
        }
Example #4
0
 public AccountService(IIdentityService identityService, ISessionStateService sessionStateService, ICredentialStore credentialStore)
 {
     _identityService     = identityService;
     _sessionStateService = sessionStateService;
     _credentialStore     = credentialStore;
     if (_sessionStateService.SessionState.ContainsKey(SignedInUserKey))
     {
         _signedInUser = _sessionStateService.SessionState[SignedInUserKey] as CDUserInfo;
     }
     if (_sessionStateService.SessionState.ContainsKey(UserIdKey))
     {
         _userId = _sessionStateService.SessionState[UserIdKey].ToString();
     }
     if (_sessionStateService.SessionState.ContainsKey(PasswordKey))
     {
         _password = _sessionStateService.SessionState[PasswordKey].ToString();
     }
 }
Example #5
0
        async public System.Threading.Tasks.Task SynchronizeAllAsync()
        {
            try
            {
                var connectionProfile = NetworkInformation.GetInternetConnectionProfile();
                if (connectionProfile == null || connectionProfile.GetNetworkConnectivityLevel() != NetworkConnectivityLevel.InternetAccess)
                {
                    return;
                }

                if (_userInfo == null)
                {
                    this._userInfo = JsonConvert.DeserializeObject <CDUserInfo>(ApplicationData.Current.RoamingSettings.Values[Constants.UserInfo].ToString());
                }

                Synchronize(async() =>
                {
                    await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        AppSettings.Instance.IsSynchronizing = 1;
                    });


                    await this.InsertDocumentDetailsCollectedByCustomerToSvcAsync();
                    await this.GetDriverListFromSvcAsync();
                    await this.GetCourierListFromSvcAsync();
                    //await      this.InsertDocumentCollectedByDriverOrCourierToSvcAsync();
                    await this.UpdateDeliveryDetailAsync();
                    await this.InsertDocumentDeliveredByDriverOrCourierToSvcAsync();
                    await this.UpdateTaskStatusAsync();
                    await this.GetCollectedFromSvcAsync();

                    await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        AppSettings.Instance.IsSynchronizing = 0;
                    });
                });
            }
            catch (Exception ex)
            {
                this.SendMessageToUIThread(ex.Message);
            }
        }
Example #6
0
        async public Task <Tuple <CDUserInfo, string> > SignInAsync(string userId, string password, bool isCredentialStore)
        {
            try
            {
                var userInfo = new CDUserInfo {
                    Name = userId, UserId = userId
                };
                var result = await _identityService.LogonAsync(userId, password);

                if (result.Item1 == null)
                {
                    return(new Tuple <CDUserInfo, string>(null, result.Item2));
                }

                CDUserInfo previousUser = _signedInUser;
                _signedInUser = result.Item1.UserInfo;

                _sessionStateService.SessionState[SignedInUserKey] = _signedInUser;
                _userId   = userId;
                _password = password;
                _sessionStateService.SessionState[UserIdKey]   = userId;
                _sessionStateService.SessionState[PasswordKey] = password;

                if (isCredentialStore)
                {
                    _credentialStore.SaveCredentials(PasswordVaultResourceName, userId, password);
                }

                if (previousUser == null)
                {
                    RaiseUserChanged(_signedInUser, previousUser);
                }
                else if (_signedInUser != null && _signedInUser.UserId != previousUser.UserId)
                {
                    RaiseUserChanged(_signedInUser, previousUser);
                }
                return(new Tuple <CDUserInfo, string>(_signedInUser, ""));
            }
            catch (Exception ex)
            {
                return(new Tuple <CDUserInfo, string>(null, ex.Message));
            }
        }
Example #7
0
        public async System.Threading.Tasks.Task <MzkCollectDeliveryServiceClient> ConnectAsync(string userName, string password, IEventAggregator eventAggregator, string domain = "lfmd")
        {
            try
            {
                try
                {
                    if (this._userInfo == null)
                    {
                        this._userInfo = JsonConvert.DeserializeObject <CDUserInfo>(ApplicationData.Current.RoamingSettings.Values[Constants.UserInfo].ToString());
                    }
                }
                catch (Exception)
                {
                }
                _eventAggregator = eventAggregator;
                BasicHttpBinding basicHttpBinding = new BasicHttpBinding()
                {
                    MaxBufferPoolSize      = int.MaxValue,
                    MaxBufferSize          = int.MaxValue,
                    MaxReceivedMessageSize = int.MaxValue,
                    OpenTimeout            = new TimeSpan(2, 0, 0),
                    ReceiveTimeout         = new TimeSpan(2, 0, 0),
                    SendTimeout            = new TimeSpan(2, 0, 0),
                    AllowCookies           = true
                };

                basicHttpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
                basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;//http://SRFMLAXTEST01/MicrosoftDynamicsAXAif60/CollectDeliveryService/xppservice.svc
                _client = new MzkCollectDeliveryServiceClient(basicHttpBinding, new EndpointAddress("http://srfmlbispstg01.lfmd.co.za/MicrosoftDynamicsAXAif60/CollectDeliverService/xppservice.svc"));
                _client.ClientCredentials.UserName.UserName = domain + "\"" + userName;
                _client.ClientCredentials.UserName.Password = password;
                _client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
                _client.ClientCredentials.Windows.ClientCredential          = new NetworkCredential(userName, password, domain);
                return(_client);
            }
            catch (Exception ex)
            {
                Util.ShowToast(ex.Message);
                return(_client);
            }
        }
Example #8
0
        async public System.Threading.Tasks.Task GetDriverListFromSvcAsync()
        {
            try
            {
                var connectionProfile = NetworkInformation.GetInternetConnectionProfile();
                if (connectionProfile == null || connectionProfile.GetNetworkConnectivityLevel() != NetworkConnectivityLevel.InternetAccess || _userInfo.CDUserType != CDUserType.Driver)
                {
                    return;
                }

                if (_userInfo == null)
                {
                    _userInfo = JsonConvert.DeserializeObject <CDUserInfo>(ApplicationData.Current.RoamingSettings.Values[Constants.UserInfo].ToString());
                }
                var courierData = (await SqliteHelper.Storage.LoadTableAsync <Driver>());
                var result      = await _client.getDriversAsync(_userInfo.CompanyId);

                if (result.response != null)
                {
                    foreach (var mzk in result.response)
                    {
                        if (courierData != null && courierData.Any(a => a.UserID == mzk.parmUserID))
                        {
                            await SqliteHelper.Storage.UpdateSingleRecordAsync <Driver>(new Driver { UserID = mzk.parmUserID, UserName = mzk.parmUserName, Address = mzk.parmAddress });
                        }
                        else
                        {
                            await SqliteHelper.Storage.InsertSingleRecordAsync <Driver>(new Driver { UserID = mzk.parmUserID, UserName = mzk.parmUserName, Address = mzk.parmAddress });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.SendMessageToUIThread(ex.Message);
            }
        }
Example #9
0
        public async System.Threading.Tasks.Task UpdateTaskStatusAsync()
        {
            try
            {
                var connectionProfile = NetworkInformation.GetInternetConnectionProfile();
                if (connectionProfile == null || connectionProfile.GetNetworkConnectivityLevel() != NetworkConnectivityLevel.InternetAccess)
                {
                    return;
                }
                if (_userInfo == null)
                {
                    _userInfo = JsonConvert.DeserializeObject <CDUserInfo>(ApplicationData.Current.RoamingSettings.Values[Constants.UserInfo].ToString());
                }
                var tasks = (await SqliteHelper.Storage.LoadTableAsync <CollectDeliveryTask>()).Where(w => w.UserID == _userInfo.UserId && w.IsNotSyncedWithAX);

                ObservableCollection <MZKCollectDeliverTasksContract> mzkTasks = new ObservableCollection <MZKCollectDeliverTasksContract>();
                Dictionary <string, EEPActionStep> actionStepMapping           = new Dictionary <string, EEPActionStep>();

                //actionStepMapping.Add(CDTaskStatus.AwaitLicenceDisc, EEPActionStep.AwaitLicenceDisc);


                switch (_userInfo.CDUserType)
                {
                case CDUserType.Driver:

                    actionStepMapping.Add(CDTaskStatus.AwaitDeliveryConfirmation, EEPActionStep.AwaitDriverCollection);
                    actionStepMapping[CDTaskStatus.AwaitInvoice] = EEPActionStep.AwaitDriverCollectionLicenseDisc;
                    actionStepMapping.Add(CDTaskStatus.Completed, EEPActionStep.AwaitDeliveryConfirmation);
                    tasks = tasks.Where(w => w.Status == CDTaskStatus.AwaitDeliveryConfirmation || w.Status == CDTaskStatus.Completed ||
                                        w.Status == CDTaskStatus.AwaitInvoice);
                    break;

                case CDUserType.Courier:

                    actionStepMapping.Add(CDTaskStatus.AwaitDeliveryConfirmation, EEPActionStep.AwaitCourierCollection);
                    actionStepMapping.Add(CDTaskStatus.AwaitInvoice, EEPActionStep.AwaitDeliveryConfirmationCourier);
                    tasks = tasks.Where(w => w.Status == CDTaskStatus.AwaitDeliveryConfirmation || w.Status == CDTaskStatus.AwaitInvoice);
                    break;

                case CDUserType.Customer:
                    actionStepMapping.Add(CDTaskStatus.Completed, EEPActionStep.AwaitCollectionDetail);
                    tasks = tasks.Where(w => w.Status == CDTaskStatus.Completed);
                    break;
                }

                if (tasks != null)
                {
                    foreach (var task in tasks)
                    {
                        //if (task.ServiceId == "Licence Dup")
                        //{
                        //    actionStepMapping[CDTaskStatus.AwaitInvoice] = EEPActionStep.AwaitDriverCollectionLicenseDisc;
                        //}
                        mzkTasks.Add(
                            new MZKCollectDeliverTasksContract
                        {
                            parmCaseId           = task.CaseNumber,
                            parmCaseServiceRecID = task.CaseServiceRecID,
                            parmServiceRecID     = task.ServiceRecID,
                            parmStatusDueDate    = task.StatusDueDate,
                            parmEEPActionStep    = actionStepMapping[task.Status],
                            parmServiceId        = task.ServiceId
                        });
                    }
                    if (mzkTasks.Count > 0)
                    {
                        var res = await _client.updateStatusListAsync(mzkTasks, (MzkLoginType)Enum.Parse(typeof(MzkLoginType), _userInfo.CDUserType.ToString()), _userInfo.CompanyId);

                        if (res.response != null && res.response.Any())
                        {
                            foreach (var task in tasks)
                            {
                                if (res.response.Any(a => a.parmCaseId == task.CaseNumber))
                                {
                                    if (task.TaskType == CDTaskType.None)
                                    {
                                        await SqliteHelper.Storage.DeleteSingleRecordAsync <CollectDeliveryTask>(task);
                                    }
                                    else
                                    {
                                        task.IsNotSyncedWithAX = false;
                                        await SqliteHelper.Storage.UpdateSingleRecordAsync <CollectDeliveryTask>(task);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                this.SendMessageToUIThread(ex.Message);
            }
        }
Example #10
0
        async public System.Threading.Tasks.Task <List <CollectDeliveryTask> > SyncTasksFromSvcAsync()
        {
            List <CollectDeliveryTask> taskInsertList = new List <CollectDeliveryTask>();

            try
            {
                var connectionProfile = NetworkInformation.GetInternetConnectionProfile();
                if (connectionProfile == null || connectionProfile.GetNetworkConnectivityLevel() != NetworkConnectivityLevel.InternetAccess)
                {
                    return(null);
                }

                if (_userInfo == null)
                {
                    _userInfo = JsonConvert.DeserializeObject <CDUserInfo>(ApplicationData.Current.RoamingSettings.Values[Constants.UserInfo].ToString());
                }

                var result = await _client.getTasksAsync(_userInfo.UserId, _userInfo.CompanyId);

                var taskData = await SqliteHelper.Storage.LoadTableAsync <CollectDeliveryTask>();

                ObservableCollection <long> caseCategoryRecIdList = new ObservableCollection <long>();
                if (result.response != null)
                {
                    foreach (var mzkTask in result.response.GroupBy(g => g.parmCaseId).Select(s => s.First()))
                    {
                        var taskTosave = new CollectDeliveryTask
                        {
                            CaseNumber           = mzkTask.parmCaseId,
                            Address              = mzkTask.parmContactPersonAddress,
                            CustomerName         = mzkTask.parmCustName,
                            CustomerNumber       = mzkTask.parmContactPersonPhone,
                            Status               = mzkTask.parmStatus,
                            StatusDueDate        = mzkTask.parmStatusDueDate,
                            RegistrationNumber   = mzkTask.parmRegNo,
                            AllocatedTo          = mzkTask.parmUserID,
                            MakeModel            = mzkTask.parmMake + Environment.NewLine + mzkTask.parmModel,
                            CaseCategoryRecID    = mzkTask.parmCaseCategoryRecID,
                            DeliveryDate         = mzkTask.parmDeliveryDateTime,
                            EmailId              = mzkTask.parmCustomerEmail,
                            CustPartyId          = mzkTask.parmCustPartyId,
                            CaseRecID            = mzkTask.parmCaseRecID,
                            CaseServiceRecID     = mzkTask.parmCaseServiceRecID,
                            TaskType             = (CDTaskType)Enum.Parse(typeof(CDTaskType), mzkTask.parmCollectDeliverType.ToString()),
                            CustomerId           = mzkTask.parmCustAccount,
                            ServiceId            = mzkTask.parmServiceId,
                            ServiceRecID         = mzkTask.parmServiceRecID,
                            UserID               = _userInfo.UserId,
                            SerialNumber         = mzkTask.parmSerialNumber,
                            ContactName          = mzkTask.parmContactPersonName,
                            ContactPersonAddress = mzkTask.parmContactPersonAddress,
                            DocumentType         = mzkTask.parmDocuTypeID,
                            DocumentName         = mzkTask.parmDocuName,
                        };

                        taskInsertList.Add(taskTosave);

                        caseCategoryRecIdList.Add(mzkTask.parmCaseCategoryRecID);
                        await this.GetCustomerListFromSvcAsync(mzkTask.parmCustAccount);
                    }
                    await SqliteHelper.Storage.DropnCreateTableAsync <CollectDeliveryTask>();

                    await SqliteHelper.Storage.InsertAllAsync(taskInsertList);
                }
                await GetCollectedFromSvcAsync();
            }
            catch (Exception ex)
            {
                this.SendMessageToUIThread(ex.Message);
            }
            return(taskInsertList);
        }