/// <summary> /// Updates the task detail in timesheet. /// </summary> /// <param name="taskDetail">The taskd detail.</param> /// <param name="accessToken">The access token.</param> /// <returns> /// the task details object /// </returns> public async Task<TaskDetails> InsertTaskDetail(TaskDetail taskDetail, string accessToken) { if (taskDetail != null && !string.IsNullOrEmpty(accessToken)) { var authorizationHeaderValue = new AuthenticationHeaderValue(AuthorizationScheme, accessToken); return await Task.Run(() => this.httpClientHelper.PostData<TaskDetails, TaskDetail>(this.GetUri(FillTimesheetResource), taskDetail, authorizationHeaderValue)); } return null; }
/// <summary> /// Validates the timesheet details. /// </summary> /// <param name="taskDetail">The task detail.</param> /// <returns>The Validation Message</returns> public string ValidateTimesheetDetails(TaskDetail taskDetail, bool checkFeatureList) { if (taskDetail.Date.Date > DateTime.Now.Date) { return InvalidDateMessage; } if (taskDetail.ProjectId == DefaultId) { return InvalidProjectIdMessage; } if (taskDetail.FeatureId == DefaultId && checkFeatureList) { return InvalidFeatureIdMessage; } if (!checkFeatureList) { taskDetail.FeatureId = null; } if (taskDetail.CategoryId == DefaultId) { return InvalidWorkDetailIdMessage; } if (taskDetail.HoursReported <= 0 || !IsValidHourCount(taskDetail.HoursReported.ToString()) || taskDetail.HoursReported > 9) { return InvalidHoursReportedMessage; } if (string.IsNullOrEmpty(taskDetail.Description)) { return InvalidDescriptionMessage; } return IsValidWorkDetailMessage; }
/// <summary> /// Maps the task detail. /// </summary> /// <param name="taskDetail">The task detail.</param> private void MapTaskDetail(TaskDetail taskDetail) { if (timeSheetDetail != null) { try { taskDetail.ApplicationType = ApplicationType.WindowsPhone; var spinnerWorkCategoryValue = WorkCategoryListPicker.SelectedItem as TypeInfo; taskDetail.CategoryId = spinnerWorkCategoryValue.Id; taskDetail.Date = DateTime.Parse(ApplicationData.CurrentDate, CultureInfoUS); taskDetail.Description = txtDescription.Text; taskDetail.DeveloperId = int.Parse(ApplicationData.User.UserId); var featureValue = (FeatureListPicker.SelectedItem as TypeInfo).Id; taskDetail.FeatureId = featureList.Count <= 1 && featureValue == -1 ? (int?)null : featureValue; taskDetail.HoursReported = decimal.Parse(txtHourCount.Text); var projectValue = ProjectListPicker.SelectedItem as ProjectDetail; taskDetail.ProjectId = projectValue.Id; } catch (Exception ex) { } } }
/// <summary> /// Selects the last task details. /// </summary> /// <param name="lastTaskDetail">The last task detail.</param> private void SelectLastTaskDetails(TaskDetail lastTaskDetail) { if (lastTaskDetail != null) { var projectDetail = timeSheetDetail.ProjectList.Where(project => project.Id == lastTaskDetail.ProjectId).FirstOrDefault(); ProjectListPicker.SelectedItem = projectDetail; var workCategory = timeSheetDetail.WorkCategories.Where(category => category.Id == lastTaskDetail.CategoryId).FirstOrDefault(); WorkCategoryListPicker.SelectedItem = workCategory; } }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> private async void btnSave_Click(object sender, System.Windows.RoutedEventArgs e) { progressMask.Show(); try { if (NetworkInterface.GetIsNetworkAvailable()) { TaskDetail taskDetail = new TaskDetail(); MapTaskDetail(taskDetail); var checkFeatureList = featureList.Count > 1; var isTaskDetailValidated = this.timesheetRepository.ValidateTimesheetDetails(taskDetail, checkFeatureList); if (!string.IsNullOrEmpty(isTaskDetailValidated) && isTaskDetailValidated == IsValidWorkDetailMessage) { await timesheetRepository.InsertTaskDetail(taskDetail, ApplicationData.User.Token); ////this.ShowToastNotification("Hour(s) logged successfully."); if (NavigationService.CanGoBack) { PhoneApplicationService.Current.State["ToastNotification"] = "Hour(s) logged successfully."; ApplicationData.IsRedirectedFromTimesheet = true; NavigationService.GoBack(); } } else { this.ShowToastNotification(isTaskDetailValidated); } } } catch (Exception ex) { } finally { progressMask.Hide(); } }
/// <summary> /// Handles the Click event of the btnSaveNew control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> private async void btnSaveNew_Click(object sender, System.Windows.RoutedEventArgs e) { progressMask.Show(); try { if (NetworkInterface.GetIsNetworkAvailable()) { TaskDetail taskDetail = new TaskDetail(); MapTaskDetail(taskDetail); var checkFeatureList = featureList.Count > 1; var isTaskDetailValidated = this.timesheetRepository.ValidateTimesheetDetails(taskDetail, checkFeatureList); if (!string.IsNullOrEmpty(isTaskDetailValidated) && isTaskDetailValidated == IsValidWorkDetailMessage) { var taskDetails = await timesheetRepository.InsertTaskDetail(taskDetail, ApplicationData.User.Token); txtDescription.Text = string.Empty; txtHourCount.Text = "0"; if (taskDetails != null) { var hourCount = taskDetails.TotalTimesheetHours - (int)taskDetails.TotalTimesheetHours != 0 ? taskDetails.TotalTimesheetHours : (int)taskDetails.TotalTimesheetHours; txtTotalHoursCount.Text = hourCount.ToString(); } ShowToastNotification("Hour(s) logged successfully."); } else { ShowToastNotification(isTaskDetailValidated); } } } catch (Exception ex) { } finally { progressMask.Hide(); } }
private void SelectLastTaskDetails(TaskDetail lastTaskDetail) { if (lastTaskDetail != null) { ////ApplicationData.CurrentDate = lastTaskDetail.Date.ToString(DateFormat); ////SetHeaderDate(ApplicationData.CurrentDate); var projectDetail = timeSheetDetail.ProjectList.Where(project => project.Id == lastTaskDetail.ProjectId).FirstOrDefault(); ProjectListPicker.SelectedItem = projectDetail; var workCategory = timeSheetDetail.WorkCategories.Where(category => category.Id == lastTaskDetail.CategoryId).FirstOrDefault(); WorkCategoryListPicker.SelectedItem = workCategory; } }
/// <summary> /// Maps the task detail. /// </summary> /// <param name="taskDetail">The task detail.</param> private void MapTaskDetail(TaskDetail taskDetail) { if (timeSheetDetail != null) { try { taskDetail.ApplicationType = ApplicationType.Android; taskDetail.VersionNumber = GetVersionNumber(); var spinnerWorkCategoryValue = timeSheetDetail.WorkCategories[(int)spnWorkCategory.SelectedItemId].Id; taskDetail.CategoryId = spinnerWorkCategoryValue; taskDetail.Date = DateTime.Parse(ApplicationData.CurrentDate, us); taskDetail.Description = txtDescription.Text; taskDetail.DeveloperId = int.Parse(ApplicationData.User.UserId); var featureValue = featureList[(int)spnFeature.SelectedItemId].Id; taskDetail.FeatureId = featureList.Count <= 1 && featureValue == -1 ? (int?)null : featureValue; taskDetail.HoursReported = decimal.Parse(txtHourCount.Text); var projectValue = timeSheetDetail.ProjectList[(int)spnProject.SelectedItemId].Id; taskDetail.ProjectId = projectValue; } catch (Exception ex) { } } }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private async void btnSave_Click(object sender, EventArgs e) { var progress = ProgressDialog.Show(this, GetString(Resource.String.Insight), GetString(Resource.String.PleaseWait), true); try { if (!IfNetworkAvailable()) { progress.Dismiss(); return; } TaskDetail taskDetail = new TaskDetail(); MapTaskDetail(taskDetail); var checkFeatureList = featureList.Count > 1; var isTaskDetailValidated = this.timesheetRepository.ValidateTimesheetDetails(taskDetail, checkFeatureList); if (!string.IsNullOrEmpty(isTaskDetailValidated) && isTaskDetailValidated == IsValidWorkDetailMessage) { await timesheetRepository.InsertTaskDetail(taskDetail, ApplicationData.User.Token); Toast.MakeText(this, GetString(Resource.String.SuccessHoursLogged), ToastLength.Long).Show(); StartActivity(typeof(TaskDetailActivity)); } else { Toast.MakeText(this, isTaskDetailValidated, ToastLength.Long).Show(); } progress.Dismiss(); } catch (Exception ex) { progress.Dismiss(); } }
/// <summary> /// Handles the Click event of the btnSaveNew control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private async void btnSaveNew_Click(object sender, EventArgs e) { var progress = ProgressDialog.Show(this, GetString(Resource.String.Insight), GetString(Resource.String.PleaseWait), true); try { if (!IfNetworkAvailable()) { progress.Dismiss(); return; } TaskDetail taskDetail = new TaskDetail(); MapTaskDetail(taskDetail); var checkFeatureList = featureList.Count > 1; var isTaskDetailValidated = this.timesheetRepository.ValidateTimesheetDetails(taskDetail, checkFeatureList); if (!string.IsNullOrEmpty(isTaskDetailValidated) && isTaskDetailValidated == IsValidWorkDetailMessage) { var taskDetails = await timesheetRepository.InsertTaskDetail(taskDetail, ApplicationData.User.Token); txtDescription.Text = string.Empty; txtHourCount.Text = "0"; if (taskDetails != null) { var hourCount = taskDetails.TotalTimesheetHours - (int)taskDetails.TotalTimesheetHours != 0 ? taskDetails.TotalTimesheetHours : (int)taskDetails.TotalTimesheetHours; txtTotalHoursCount.Text = hourCount.ToString(); } Toast.MakeText(this, GetString(Resource.String.SuccessHoursLogged), ToastLength.Long).Show(); } else { Toast.MakeText(this, isTaskDetailValidated, ToastLength.Long).Show(); } progress.Dismiss(); } catch (Exception ex) { progress.Dismiss(); } }
/// <summary> /// Selects the last task details. /// </summary> private void SelectLastTaskDetails(TaskDetail lastTaskDetail) { if (lastTaskDetail != null) { var projectDetail = timeSheetDetail.ProjectList.Where(project => project.Id == lastTaskDetail.ProjectId).FirstOrDefault(); spnProject.SetSelection(((CustomArrayAdapter<ProjectDetail>)spnProject.Adapter).GetPosition(projectDetail)); var workCategory = timeSheetDetail.WorkCategories.Where(category => category.Id == lastTaskDetail.CategoryId).FirstOrDefault(); spnWorkCategory.SetSelection(((CustomArrayAdapter<TypeInfo>)spnWorkCategory.Adapter).GetPosition(workCategory)); } }