Hi
I am showing the payslip using wpf mvvm.First time its showing payslip.
i selected another payslip but wpfpdfviewer shows the previous payslip.
The code is
public PdfView(PdfViewModel viewModel)
{
InitializeComponent();
this.DataContext = viewModel;
string Exepath = System.Reflection.Assembly.GetExecutingAssembly().Location;
string Directory = System.IO.Path.GetDirectoryName(Exepath);
string Path = Directory + "\\Employee.pdf" ;
pdfViewer.LoadFile(Path);
if(System.IO.File.Exists(Path))
{
System.IO.File.Delete(Path);
}
}
But in the save path, its showing corret month payslip.
In the Ui,its showing whatever is showing for the firstime ,every time its showing the first time payslip.
private void ExecuteGetPayslip()
{
if (AnnualData == null || AnnualContextItem.Id == -1)
{
MessageBox.Show("Please Select Payslip.");
}
else
{
AppController.UserInstance.InitializeLoader(Resources.DefaultLoadingMessage);
UserMetadata userMetaData = AppMonitor.GetSession();
string pdfPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
if (userMetaData != null)
{
var absenceTypeWithReasonParams =
new Dictionary<string, string>();
var absenceTypeWithReasonBodyParams =
new Dictionary<string, string>();
absenceTypeWithReasonParams.Add(Resources.UserId, userMetaData.userId);
absenceTypeWithReasonParams.Add(Resources.SessionToken, userMetaData.sessionToken);
absenceTypeWithReasonParams.Add(Resources.DeviceType, Resources.DeviceName);
absenceTypeWithReasonParams.Add("personId", personId);
absenceTypeWithReasonParams.Add("actionContextId", Convert.ToString(AnnualContextItem.Id));
var apiServiceHelper = new CommonServiceHelper();
var response = apiServiceHelper.SendMessage(ServiceUrlConstants.GetPaySlipRequestId(), absenceTypeWithReasonParams);
if (string.IsNullOrEmpty(response))
RaiseNotifyValidation(Resources.Failure, Resources.ErrorMessage);
var obj = JsonHelper.ConvertJsonStringToObject<LoginResponse>(response);
if (obj.Status == Resources.Success)
{
RequestId = Convert.ToString(obj.Data.RequestId);
}
else
{
AppController.UserInstance.UnInitilizeLoader();
RaiseNotifyValidation(obj.Status, obj.Message);
}
var pdfResponse = apiServiceHelper.PostRequest(ServiceUrlConstants.getPaySlipStatus(), absenceTypeWithReasonParams, absenceTypeWithReasonBodyParams, "" + "?reqId=" + Convert.ToString(RequestId));
if (!string.IsNullOrEmpty(pdfResponse))
{
var pdfobj = JsonHelper.ConvertJsonStringToObject<PayslipResponse>(pdfResponse);
if (pdfobj.Data.PaySlipStatus == "Failure")
{
RaiseNotifyValidation(obj.Status, "Payslip is not generated for this user.");
AppController.UserInstance.UnInitilizeLoader();
}
else if (pdfobj.Data.PaySlipStatus == "Completed")
{
absenceTypeWithReasonBodyParams.Add("reqId", Convert.ToString(RequestId));
var pdfresponse = apiServiceHelper.PostRequestForByteArray(ServiceUrlConstants.GetPaySlip(), absenceTypeWithReasonParams, absenceTypeWithReasonBodyParams);
System.IO.File.WriteAllBytes(pdfPath + "\\Employee.pdf", pdfresponse);
var regionManager = (RegionManager)ServiceLocator.Current.GetInstance<IRegionManager>();
var AbsenceModuleView = new Uri(Resources.PdfView, UriKind.Relative);
regionManager.RequestNavigate(RegionNames.MainContentRegion, AbsenceModuleView);
AppController.UserInstance.UnInitilizeLoader();
}
else
{
int x = 0;
do
{
AppController.UserInstance.InitializeLoader(Resources.DefaultLoadingMessage);
pdfResponse = apiServiceHelper.PostRequest(ServiceUrlConstants.getPaySlipStatus(), absenceTypeWithReasonParams, absenceTypeWithReasonBodyParams, "" + "?reqId=" + Convert.ToString(RequestId));
pdfobj = JsonHelper.ConvertJsonStringToObject<PayslipResponse>(pdfResponse);
x++;
} while (pdfobj.Data.PaySlipStatus != "Completed");
absenceTypeWithReasonBodyParams.Add("reqId", Convert.ToString(RequestId));
var pdfresponse = apiServiceHelper.PostRequestForByteArray(ServiceUrlConstants.GetPaySlip(), absenceTypeWithReasonParams, absenceTypeWithReasonBodyParams);
System.IO.File.WriteAllBytes(pdfPath + "\\Employee.pdf", pdfresponse);
var regionManager = (RegionManager)ServiceLocator.Current.GetInstance<IRegionManager>();
var AbsenceModuleView = new Uri(Resources.PdfView, UriKind.Relative);
regionManager.RequestNavigate(RegionNames.MainContentRegion, AbsenceModuleView);
AppController.UserInstance.UnInitilizeLoader();
}
}
else
{
RaiseNotifyValidation(Resources.Failure, Resources.ErrorMessage);
}
AppController.UserInstance.UnInitilizeLoader();
}
}
}
Can you please help me?