public void Init() { var dateTimeOffset = new DateTimeOffset(DateTime.UtcNow); var alertDateTimeOffset = new DateTimeOffset(DateTime.UtcNow.AddHours(5)); _task = new DiaTask { Id = Guid.NewGuid().ToString(), UserId = null, // intentionally null since we can't set user claims. TaskDescription = "Here's my task description.", DueDateTime = dateTimeOffset, AlertTimes = new List <AlertTime> { new AlertTime { Id = Guid.NewGuid().ToString(), Time = alertDateTimeOffset } }, Comments = new List <Comment> { new Comment { Id = Guid.NewGuid().ToString(), Text = "Hi" } } }; _comment = new Comment { Id = Guid.NewGuid().ToString(), Text = "Hi2" }; _alert = new AlertTime { Time = DateTimeOffset.UtcNow.AddHours(5) }; }
public async Task AddAlertAsync(string taskId, AlertTime alert) { if (alert.Time <= DateTimeOffset.UtcNow) { throw new ArgumentException("Alert time cannot be in the past."); } try { var task = await FindTaskByIdForUserAsync(taskId, alert.UserId).ConfigureAwait(false); if (task == null) { throw new NoDatabaseObjectFoundException($"Task {taskId} was not found."); } task.AlertTimes.Add(alert); _doItDbContext.Entry(task).State = EntityState.Modified; await _doItDbContext.SaveChangesAsync().ConfigureAwait(false); } catch (NoDatabaseObjectFoundException) { throw; } catch (Exception e) { throw new DatabaseUpdateException(e); } }
public void AlertTime_ModelCreated_SetWorks() { var alertTime = new AlertTime { Id = Guid.NewGuid().ToString(), Time = new DateTimeOffset(DateTime.UtcNow) }; alertTime.Should().NotBeNull(); }
public async Task TaskService_AddAlert_AlertAddedInDatabase() { var alertTime = new AlertTime { Time = DateTimeOffset.UtcNow.AddHours(5) }; var taskService = new TaskService(_dbContext); await taskService.AddAlertAsync(_task.Id, alertTime); _dbContext.Tasks.FirstOrDefault(x => x.Id == _task.Id).AlertTimes.Should().Contain(alertTime); }
public void AlertTime_ModelCreated_GetWorks() { var dateTimeOffset = new DateTimeOffset(DateTime.UtcNow); var alertTime = new AlertTime { Id = Guid.NewGuid().ToString(), Time = dateTimeOffset }; alertTime.Id.Should().NotBeNull(); alertTime.Time.Should().Be(dateTimeOffset); }
public async Task <IActionResult> PostAlertsAsync(string taskId, [FromBody] AlertTime alert) { try { alert.UserId = UserId; await _taskService.AddAlertAsync(taskId, alert).ConfigureAwait(false); return(Ok()); } catch (NoDatabaseObjectFoundException e) { return(NotFound(e.Message)); } catch (DatabaseUpdateException e) { return(BadRequest(e.Message)); } catch (ArgumentException e) { return(BadRequest(e.Message)); } }
public async Task <IActionResult> UpdateAlertAsync(string taskId, string alertId, [FromBody] AlertTime alert) { try { alert.UserId = UserId; alert.Id = alertId; // TODO: Is this needed, or will the client send the comment across with the Id already assigned? await _taskService.UpdateAlertAsync(taskId, alert).ConfigureAwait(true); return(Ok()); } catch (NoDatabaseObjectFoundException e) { return(NotFound(e.Message)); } catch (DatabaseUpdateException e) { return(BadRequest(e.Message)); } catch (ArgumentException e) { return(BadRequest(e.Message)); } }