private void DeleteChildContextAction_Clicked(object sender, EventArgs e) { //get entry that was selected to remove TimeEntryViewModel selectedTimeEntry = (sender as MenuItem)?.BindingContext as TimeEntryViewModel; //find corresponding collection var correspondingCollection = (this.BindingContext as TimeTrackerPageViewModel)?.TimeEntries.FirstOrDefault(x => x.Date.Equals(selectedTimeEntry?.StartTime.Date)); //remove item from list correspondingCollection?.Remove(selectedTimeEntry); //remove from parent selectedTimeEntry.parent.Entries.Remove(selectedTimeEntry); //delete item from DB selectedTimeEntry?.Delete(); //remove timeEntryParent from list if no children remain. if (!selectedTimeEntry.parent.Entries.Any()) { correspondingCollection?.Remove(selectedTimeEntry.parent); } //update view cell if still visible else { selectedTimeEntry.parent?.OnPropertyChanged(null); } }
public void StartATimeEntryWithTheSameValuesOfTheSelectedTimeEntry(string description, long projectId, long?taskId, bool billable) { if (description == null || projectId == 0) { return; } var project = Substitute.For <IDatabaseProject>(); project.Id.Returns(projectId); var timeEntry = Substitute.For <IDatabaseTimeEntry>(); timeEntry.Description.Returns(description); timeEntry.Billable.Returns(billable); timeEntry.Project.Returns(project); timeEntry.TaskId.Returns(taskId); timeEntry.Stop.Returns(DateTimeOffset.Now); var timeEntryViewModel = new TimeEntryViewModel(timeEntry); ViewModel.ContinueTimeEntryCommand.ExecuteAsync(timeEntryViewModel).Wait(); DataSource.TimeEntries.Received().Start(Arg.Is <StartTimeEntryDTO>(dto => dto.Description == description && dto.Billable == billable && dto.ProjectId == projectId && dto.TaskId == taskId )).Wait(); }
public CreateTimeEntryPage() { NavigationPage.SetBackButtonTitle(this, ""); //HockeyApp.MetricsManager.TrackEvent("TimeEntriesPage Initialize"); InitializeComponent(); viewModel = new TimeEntryViewModel(); viewModel.Date = DateTime.Now.Date; StartLoading(); BindingContext = viewModel; if (Device.RuntimePlatform.ToLower() == "android") { sfProjects.ShowHint = true; sfCompanies.ShowHint = true; sfTasks.ShowHint = true; sfTimeCode.ShowHint = true; cmbProjects.Margin = new Thickness(10, 0, 10, 0); cmbCompanies.Margin = new Thickness(10, 0, 10, 0); cmbTasks.Margin = new Thickness(10, 0, 10, 0); cmbTimeCode.Margin = new Thickness(10, 0, 10, 0); cmbDate.Margin = new Thickness(10, 0, 10, 0); } else { sfProjects.ShowHint = false; sfCompanies.ShowHint = false; sfTasks.ShowHint = false; sfTimeCode.ShowHint = false; } }
// POST api/timeentries public IHttpActionResult Post([FromBody] TimeEntryViewModel viewModel) { try { if (viewModel == null) { return(BadRequest(ModelState)); } var currentUser = GetCurrentUser(); ValidateViewModel(viewModel, _repository, currentUser); if (ModelState.IsValid) { var timeEntry = viewModel.GetModel(currentUser); _repository.SaveTimeEntry(timeEntry, currentUser); var uriString = Url.Link("DefaultApi", new { controller = "TimeEntries", id = timeEntry.TimeEntryId }); return(Created(uriString, new { TimeEntryId = timeEntry.TimeEntryId })); } else { return(Error(ModelState)); } } catch (Exception exc) { return(InternalServerError(exc)); } }
public async Task <ActionResult> CreateTimeEntry(TimeEntryViewModel model) { var url = "https://travel2pay.openproject.com/api/v3/time_entries"; var createTimeEntryRequest = new OPCreateTimeEntryRequest() { Comment = new OPCreateTimeEntryRequestComment { Raw = model.Comment }, Hours = $"PT{model.Hours}H", Links = new OPCreateTimeEntryModelLink() { Activity = new OPCreateTimeEntryModelActivity { Href = $"/api/v3/time_entries/activities/{model.ActivityId}" }, Project = new OPCreateTimeEntryModelProject { Href = "/api/v3/projects/2" }, WorkPackage = new OPCreateTimeEntryModelWorkPackage { Href = $"/api/v3/work_packages/{model.WorkPackageId}" } }, SpentOn = model.SpentOn.ToString("yyyy-MM-dd") }; var timeEntry = await _httpClientService .Create(Request.Headers["openProjectAPIKey"].First()) .Post <OPCreateTimeEntryRequest, OpCreateTimeEntryResponse>(url, createTimeEntryRequest); return(Ok(timeEntry)); }
public CreateTimeEntryPage(ProjectInsight.Models.Tasks.Task task) { //HockeyApp.MetricsManager.TrackEvent("TimeEntriesPage Initialize from Task"); this.selTask = task; InitializeComponent(); gvTE.RowDefinitions[0].Height = 0; gvTE.RowDefinitions[1].Height = 0; gvTE.RowDefinitions[2].Height = 0; if (Device.RuntimePlatform.ToLower() == "android") { sfTimeCode.ShowHint = true; } else { sfTimeCode.ShowHint = false; } viewModel = new TimeEntryViewModel(); viewModel.Date = DateTime.Now.Date; StartLoading(); BindingContext = viewModel; }
// GET: Default/Edit/5 public ActionResult Edit(int?id) { if (id == null) { var newTimeEntry = new TimeEntryViewModel(new TimeEntry()); newTimeEntry.AllProjects = db.Projects.ToList().Select(o => new SelectListItem { Text = o.Name, Value = o.Id.ToString() }); return(View(newTimeEntry)); } var savedTimeEntry = db.TimeEntries.Include(x => x.Project).FirstOrDefault(x => x.Id == id); if (savedTimeEntry == null) { return(HttpNotFound()); } var timeEntry = new TimeEntryViewModel(savedTimeEntry); timeEntry.AllProjects = db.Projects.ToList().Select(o => new SelectListItem { Text = o.Name, Value = o.Id.ToString() }); TempData["CurrentProject"] = timeEntry.Project; return(View(timeEntry)); }
public void ShouldBeTakenFromTimeEntry(bool isInaccessible) { MockTimeEntry.Duration.Returns((long)TimeSpan.FromHours(1).TotalSeconds); MockTimeEntry.IsInaccessible.Returns(isInaccessible); var viewModel = new TimeEntryViewModel(MockTimeEntry, DurationFormat.Improved); viewModel.IsInaccessible.Should().Be(isInaccessible); }
public void ChecksIfTheTimeEntryProvidedHasANonNullProject(bool hasProject) { MockTimeEntry.Stop.Returns(DateTimeOffset.UtcNow); MockTimeEntry.Project.Returns(hasProject ? Project : null); var viewModel = new TimeEntryViewModel(MockTimeEntry); viewModel.HasProject.Should().Be(hasProject); }
public void ChecksIfTheTimeEntryProvidedHasANonNullProject(bool hasProject) { MockTimeEntry.Duration.Returns((long)TimeSpan.FromHours(1).TotalSeconds); MockTimeEntry.Project.Returns(hasProject ? Project : null); var viewModel = new TimeEntryViewModel(MockTimeEntry, DurationFormat.Improved); viewModel.HasProject.Should().Be(hasProject); }
public void ChecksDisplayNameContainsArchived(bool active) { Project.Active.Returns(active); MockTimeEntry.Duration.Returns((long)TimeSpan.FromHours(1).TotalSeconds); MockTimeEntry.Project.Returns(Project); var viewModel = new TimeEntryViewModel(MockTimeEntry, DurationFormat.Improved); viewModel.ProjectName.Contains("(archived)").Should().Be(!active); }
public async ThreadingTask MarksTheActionForOnboardingPurposes() { var threadSafeTimeEntry = Substitute.For <IThreadSafeTimeEntry>(); threadSafeTimeEntry.Duration.Returns(100); var timeEntryViewModel = new TimeEntryViewModel(threadSafeTimeEntry, DurationFormat.Improved); await ViewModel.EditCommand.ExecuteAsync(timeEntryViewModel); OnboardingStorage.Received().TimeEntryWasTapped(); }
public async ThreadingTask StartsATimeEntry() { var timeEntry = Substitute.For <IDatabaseTimeEntry>(); timeEntry.Stop.Returns(DateTimeOffset.Now); var timeEntryViewModel = new TimeEntryViewModel(timeEntry); await ViewModel.ContinueTimeEntryCommand.ExecuteAsync(timeEntryViewModel); await DataSource.TimeEntries.Start(Arg.Any <StartTimeEntryDTO>()); }
public async ThreadingTask NavigatesToTheEditTimeEntryViewModel() { var databaseTimeEntry = Substitute.For <IDatabaseTimeEntry>(); databaseTimeEntry.Stop.Returns(DateTimeOffset.Now); var timeEntryViewModel = new TimeEntryViewModel(databaseTimeEntry); await ViewModel.EditCommand.ExecuteAsync(timeEntryViewModel); await NavigationService.Received().Navigate(typeof(EditTimeEntryViewModel), Arg.Is <long>(p => p == databaseTimeEntry.Id)); }
public async ThreadingTask DoesNotHardDeletesTheTimeEntryWhenNotCallingFinilizeDelayDeleteTimeEntryIfNeeded() { var timeEntryA = new TimeEntryViewModel(new MockTimeEntry { Id = 1, Duration = 123, TagIds = Array.Empty <long>(), Workspace = new MockWorkspace() }, DurationFormat.Classic); var observableA = viewModel.DelayDeleteTimeEntry.Execute(timeEntryA); SchedulerProvider.TestScheduler.AdvanceBy(Constants.UndoTime.Ticks / 2); InteractorFactory.DidNotReceive().DeleteTimeEntry(Arg.Is(timeEntryA.Id)).Execute(); }
public async ThreadingTask NavigatesToTheEditTimeEntryViewModel() { var threadSafeTimeEntry = Substitute.For <IThreadSafeTimeEntry>(); threadSafeTimeEntry.Duration.Returns(100); var timeEntryViewModel = new TimeEntryViewModel(threadSafeTimeEntry, DurationFormat.Improved); await ViewModel.EditCommand.ExecuteAsync(timeEntryViewModel); await NavigationService.Received().Navigate <EditTimeEntryViewModel, long>( Arg.Is <long>(p => p == threadSafeTimeEntry.Id) ); }
public IActionResult CreateTimeEntry([FromBody] TimeEntryViewModel value) { if (value == null) { return(BadRequest()); } TimeEntry timeEntry = new TimeEntry(); timeEntry.MinutesWorked = value.MinutesWorked; timeEntry.ProjectId = value.ProjectId; timeEntryService.CreateTimeEntry(timeEntry); return(CreatedAtRoute("GetTimeEntry", new { id = value.Id }, value)); }
public async ThreadingTask TracksTheEventUsingTheAnaltyticsService() { var timeEntry = Substitute.For <IThreadSafeTimeEntry>(); timeEntry.Id.Returns(1); timeEntry.Duration.Returns(100); timeEntry.WorkspaceId.Returns(10); var timeEntryViewModel = new TimeEntryViewModel(timeEntry, DurationFormat.Improved); await ViewModel.DeleteCommand.ExecuteAsync(timeEntryViewModel); AnalyticsService.DeleteTimeEntry.Received().Track(); }
//private Employee employee; public IActionResult Index(string email) { timeModel = new TimeEntryViewModel(context.Employees.FirstOrDefault(empl => empl.Email == email)); if (timeModel.TimeEntries.Count > 0) { timeModel.TimeEntries = timeModel.TimeEntries.Where(entry => entry.EmployeeID == timeModel.Employee.EmployeeID).ToList();// .TimeEntries.Where(timeEntry => timeEntry.Date.Month == DateTime.Today.Month && timeEntry.Date.Year == DateTime.Today.Year).ToList(); } else { timeModel.TimeEntries = new List <TimeEntry>(); } return(View(timeModel)); }
public void DeletesTheTimeEntry(long id) { var timeEntry = Substitute.For <IDatabaseTimeEntry>(); timeEntry.Id.Returns(id); timeEntry.Duration.Returns(100); timeEntry.WorkspaceId.Returns(10); var timeEntryViewModel = new TimeEntryViewModel(timeEntry, DurationFormat.Improved); ViewModel.DeleteCommand.ExecuteAsync(timeEntryViewModel).Wait(); DataSource.TimeEntries.Received().Delete(id).Wait(); }
public IEnumerable <TimeEntryViewModel> GetAllEntriesForProject(long id) { List <TimeEntryViewModel> timeEntries = new List <TimeEntryViewModel>(); timeEntryService.GetTimeEntries(id).ToList().ForEach(t => { TimeEntryViewModel timeEntry = new TimeEntryViewModel { Id = t.Id, MinutesWorked = t.MinutesWorked, ProjectId = t.ProjectId }; timeEntries.Add(timeEntry); }); return(timeEntries); }
public void DeletesTheTimeEntry(long id) { var timeEntry = Substitute.For <IThreadSafeTimeEntry>(); timeEntry.Id.Returns(id); timeEntry.Duration.Returns(100); timeEntry.WorkspaceId.Returns(10); var timeEntryViewModel = new TimeEntryViewModel(timeEntry, DurationFormat.Improved); ViewModel.DeleteCommand.ExecuteAsync(timeEntryViewModel).Wait(); InteractorFactory.Received().DeleteTimeEntry(Arg.Is(id)); InteractorFactory.DeleteTimeEntry(timeEntry.Id).Received().Execute(); }
public IActionResult Add(TimeEntryViewModel timeEntryViewModel) { if (!ModelState.IsValid) { return(View(timeEntryViewModel)); } else { //Remove this hard coded employee ID to the employee ID that is logged in //Leave this change for later timeEntryViewModel.TimeEntry.EmployeeID = 1; _timeEntryRepository.AddNewTimeEntry(timeEntryViewModel.TimeEntry); } PopulateProjectDropDown(); return(RedirectToAction("List")); }
public async ThreadingTask DoesNotHideTheUndoUIIfAnotherItemWasDeletedWhileWaiting() { var timeEntryA = new TimeEntryViewModel(new MockTimeEntry { Id = 1, Duration = 123, TagIds = Array.Empty <long>(), Workspace = new MockWorkspace() }, DurationFormat.Classic); var timeEntryB = new TimeEntryViewModel(new MockTimeEntry { Id = 1, Duration = 123, TagIds = Array.Empty <long>(), Workspace = new MockWorkspace() }, DurationFormat.Classic); viewModel.DelayDeleteTimeEntry.Execute(timeEntryA); SchedulerProvider.TestScheduler.AdvanceBy((long)(Constants.UndoTime.Ticks * 0.5)); viewModel.DelayDeleteTimeEntry.Execute(timeEntryB); SchedulerProvider.TestScheduler.AdvanceBy((long)(Constants.UndoTime.Ticks * 0.6)); observer.Received().OnNext(true); }
public async ThreadingTask ImmediatelyHardDeletesTheTimeEntryWhenAnotherTimeEntryIsDeletedBeforeTheUndoTimeRunsOut() { var timeEntryA = new TimeEntryViewModel(new MockTimeEntry { Id = 1, Duration = 123, TagIds = Array.Empty <long>(), Workspace = new MockWorkspace() }, DurationFormat.Classic); var timeEntryB = new TimeEntryViewModel(new MockTimeEntry { Id = 1, Duration = 123, TagIds = Array.Empty <long>(), Workspace = new MockWorkspace() }, DurationFormat.Classic); var observableA = viewModel.DelayDeleteTimeEntry.Execute(timeEntryA); SchedulerProvider.TestScheduler.AdvanceBy(Constants.UndoTime.Ticks / 2); var observableB = viewModel.DelayDeleteTimeEntry.Execute(timeEntryB); await observableA; InteractorFactory.Received().DeleteTimeEntry(Arg.Is(timeEntryA.Id)).Execute(); }
public ActionResult Edit(TimeEntryViewModel timeEntryViewModel) { if (timeEntryViewModel.Id > 0) { try { //var timeEntyviewModel = new TimeEntryViewModel(); var timeEntryToUpdate = db.TimeEntries.First(i => i.Id == timeEntryViewModel.Id); timeEntryToUpdate.Hours = timeEntryViewModel.Hours; timeEntryToUpdate.Description = timeEntryViewModel.Description; timeEntryToUpdate.Date = timeEntryViewModel.Date; timeEntryToUpdate.Project = timeEntryViewModel.Project; db.Entry(timeEntryToUpdate.Project).State = EntityState.Unchanged; db.Entry(timeEntryToUpdate).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } } try { var timeEntryToSave = new TimeEntry(); timeEntryToSave.Hours = timeEntryViewModel.Hours; timeEntryToSave.Description = timeEntryViewModel.Description; timeEntryToSave.Date = timeEntryViewModel.Date; timeEntryToSave.Project = timeEntryViewModel.Project; db.TimeEntries.Add(timeEntryToSave); db.Entry(timeEntryToSave.Project).State = EntityState.Unchanged; db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public IActionResult UpdateTimeEntry(long id, [FromBody] TimeEntryViewModel value) { var timeEntry = timeEntryService.GetTimeEntry(id); if (timeEntry == null) { return(NotFound()); } if (value == null) { return(BadRequest()); } timeEntry.MinutesWorked = value.MinutesWorked; timeEntry.ProjectId = value.ProjectId; timeEntryService.UpdateTimeEntry(timeEntry); return(Ok()); }
public IActionResult GetTimeEntry(long id) { var timeEntry = timeEntryService.GetTimeEntry(id); if (timeEntry == null) { return(NotFound()); } else { TimeEntryViewModel model = new TimeEntryViewModel(); model.Id = timeEntry.Id; model.MinutesWorked = timeEntry.MinutesWorked; model.ProjectId = timeEntry.ProjectId; return(new ObjectResult(model)); } }
public IActionResult Retrieve(_RetrieveTimeEntryViewModel retrieveModel) { Employee employee = context.Employees.FirstOrDefault(empl => empl.EmployeeID == retrieveModel.EmployeeId); string employeeFirstName = string.Empty; string employeeSurname = string.Empty; if (employee.IsAdministrator && retrieveModel.Employee != "ALL") { employeeFirstName = retrieveModel.Employee.Substring(0, retrieveModel.Employee.IndexOf(',')); employeeSurname = retrieveModel.Employee.Substring(retrieveModel.Employee.IndexOf(',') + 1).Trim(); } timeModel = new TimeEntryViewModel(retrieveModel); if (timeModel.TimeEntries.Count > 0) { if (retrieveModel.Client != "ALL") { Clients client = context.Clients.FirstOrDefault(cli => cli.ClientID.ToString() == retrieveModel.Client); timeModel.TimeEntries = timeModel.TimeEntries.Where(te => te.Client == client.ClientName).ToList(); } if (retrieveModel.Contract != "ALL") { timeModel.TimeEntries = timeModel.TimeEntries.Where(te => te.Contract == retrieveModel.Contract).ToList(); } if (!employee.IsAdministrator) { timeModel.TimeEntries = timeModel.TimeEntries.Where(te => te.EmployeeID == retrieveModel.EmployeeId).ToList(); } if (retrieveModel.Employee != "ALL" && employee.IsAdministrator) { timeModel.TimeEntries = timeModel.TimeEntries.Where(te => te.EmployeeName == employeeFirstName && te.EmployeeSurname == employeeSurname).ToList(); } if (retrieveModel.Service != "ALL") { timeModel.TimeEntries = timeModel.TimeEntries.Where(te => te.Service == retrieveModel.Service).ToList(); } //timeModel.TimeEntries = timeModel.TimeEntries.Where(entry => entry.EmployeeID == timeModel.Employee.EmployeeID).ToList();// .TimeEntries.Where(timeEntry => timeEntry.Date.Month == DateTime.Today.Month && timeEntry.Date.Year == DateTime.Today.Year).ToList(); } else { timeModel.TimeEntries = new List <TimeEntry>(); } return(View("Index", timeModel)); }
public TimeEntryViewData(TimeEntryViewModel timeEntryViewModel) { TimeEntryViewModel = timeEntryViewModel; var spannableString = new SpannableStringBuilder(); if (TimeEntryViewModel.HasProject) { spannableString.Append(TimeEntryViewModel.ProjectName, new ForegroundColorSpan(Color.ParseColor(TimeEntryViewModel.ProjectColor)), SpanTypes.ExclusiveInclusive); if (!string.IsNullOrEmpty(TimeEntryViewModel.TaskName)) { spannableString.Append($": {TimeEntryViewModel.TaskName}"); } if (!string.IsNullOrEmpty(TimeEntryViewModel.ClientName)) { spannableString.Append($" {TimeEntryViewModel.ClientName}", new ForegroundColorSpan(Color.ParseColor(ClientNameColor)), SpanTypes.ExclusiveExclusive); } ProjectTaskClientText = spannableString; ProjectTaskClientVisibility = ViewStates.Visible; } else { ProjectTaskClientText = new SpannableString(string.Empty); ProjectTaskClientVisibility = ViewStates.Gone; } DurationText = TimeEntryViewModel.Duration.HasValue ? DurationAndFormatToString.Convert(TimeEntryViewModel.Duration.Value, TimeEntryViewModel.DurationFormat) : ""; DescriptionVisibility = TimeEntryViewModel.HasDescription.ToVisibility(); AddDescriptionLabelVisibility = (!TimeEntryViewModel.HasDescription).ToVisibility(); ContinueImageVisibility = TimeEntryViewModel.CanContinue.ToVisibility(); ErrorImageViewVisibility = (!TimeEntryViewModel.CanContinue).ToVisibility(); ErrorNeedsSyncVisibility = TimeEntryViewModel.NeedsSync.ToVisibility(); ContinueButtonVisibility = TimeEntryViewModel.CanContinue.ToVisibility(); BillableIconVisibility = TimeEntryViewModel.IsBillable.ToVisibility(); HasTagsIconVisibility = TimeEntryViewModel.HasTags.ToVisibility(); }