public async Task <ActionResult <Team> > CreateTeam([FromBody] NewTeam newTeam) { var user = await _timelineContext.Users.Where(x => x.Id == newTeam.UserId).Include(x => x.Affiliations) .FirstOrDefaultAsync(); if (user == null) { return(BadRequest()); } var team = newTeam.Team; team.Owner = user; team.TeamMembers = new List <Affiliation>(); var affiliation = new Affiliation { UserId = user.Id, TeamId = team.Id }; team.TeamMembers.Add(affiliation); team.InviteToken = Guid.NewGuid(); _timelineContext.Teams.Add(team); await _timelineContext.SaveChangesAsync(); _log.LogInformation("New team {id}, {name}", team.Id, team.Name); return(Ok(team)); }
public async Task <IActionResult> Create([Bind("EventID,Date,Description,TimelineID,Title")] Event @event) { if (ModelState.IsValid) { _context.Add(@event); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewData["TimelineID"] = new SelectList(_context.Timelines, "TimelineID", "TimelineID", @event.TimelineID); return(View(@event)); }
public async Task <IActionResult> Create([Bind("Credits,FocusID,Title,Description,BeginDate,EndDate")] Timeline timeline) { if (ModelState.IsValid) { _context.Add(timeline); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } PopulateFocusesDropDownList(timeline.FocusID); return(View(timeline)); }
public async Task InitializeAsync() { Db.Events.RemoveRange(Db.Events); await Db.SaveChangesAsync(); await EventsRepo.SaveEventsAsync(Events); }
public async Task <IActionResult> AddWorker([FromBody] WorkersUpdate workersUpdate) { var job = await _timelineContext.Jobs.Where(x => x.JobId == workersUpdate.JobId) .Include(x => x.AssociatedUsers).FirstOrDefaultAsync(); if (job == null) { return(BadRequest()); } Console.WriteLine($"Updating workers for {workersUpdate.JobId}"); var jobWorker = new JobWorker { JobId = workersUpdate.JobId, UserId = workersUpdate.UserId }; job.AssociatedUsers.Add(jobWorker); await _timelineContext.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> JoinBoard([FromBody] JoinBoard joinBoard) { var board = await _timelineContext.Board.Where(x => x.InviteToken == joinBoard.InviteToken) .Include(x => x.BoardMembers).FirstOrDefaultAsync(); var user = await _timelineContext.Users.Where(x => x.Id == joinBoard.UserId).FirstOrDefaultAsync(); if (board == null || user == null) { return(BadRequest()); } var boardAffiliation = new BoardAffiliation() { UserId = joinBoard.UserId, BoardId = board.Id }; board.BoardMembers.Add(boardAffiliation); Audit audit = new Audit { Action = AuditAction.UserJoinedBoard, Log = ($"{boardAffiliation.UserId} joined board {boardAffiliation.BoardId}"), Origin = AuditOrigin.BoardController, Team = null, TimeStamp = DateTime.Now, User = user }; await _auditService.CreateAudit(audit); await _timelineContext.SaveChangesAsync(); Console.WriteLine($"board affiliation {boardAffiliation.UserId} : {boardAffiliation.BoardId}"); _log.LogInformation("Creating board affiliation {userId} : {TeamId}", boardAffiliation.UserId, boardAffiliation.BoardId); return(Ok(board)); }
public async Task <int> CreateUser(User user) { PasswordHasher <User> hasher = new PasswordHasher <User>( new OptionsWrapper <PasswordHasherOptions>( new PasswordHasherOptions() { CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV2 }) ); user.Password = hasher.HashPassword(user, user.Password); _timelineContext.Users.Add(user); return(await _timelineContext.SaveChangesAsync()); }
public async Task InitializeAsync() { Db.Events.RemoveRange(Db.Events); await Db.SaveChangesAsync(); var events = new[] { new Event <string, string>("A", SpecificDate.BeforeChrist(10), SpecificDate.AnnoDomini(12)), new Event <string, string>("B", SpecificDate.BeforeChrist(20, 5)), new Event <string, string>("C", SpecificDate.AnnoDomini(2020, 1, 1), NowDate.Instance), new Event <string, string>("D", NowDate.Instance), new Event <string, string>("E", SpecificDate.BeforeChrist(100, 2, 3, 10), SpecificDate.BeforeChrist(100, 2, 3, 20)), }; await EventsRepo.SaveEventsAsync(events); }
public async Task <IActionResult> CreateAffiliation([FromBody] AffiliationPost affiliationPost) { var user = await _timelineContext.Users.Where(x => x.Id == affiliationPost.UserId) .Include(x => x.Affiliations).FirstOrDefaultAsync(); if (user == null) { return(BadRequest()); } var affiliation = new Affiliation { UserId = affiliationPost.UserId, TeamId = affiliationPost.TeamId }; user.Affiliations.Add(affiliation); await _timelineContext.SaveChangesAsync(); Console.WriteLine($"affiliation {affiliation.UserId} : {affiliation.TeamId}"); _log.LogInformation("Creating affiliation {userId} : {TeamId}", affiliation.UserId, affiliation.TeamId); return(Ok()); }
public async Task Save_new_events() { // Arrange _db.Events.RemoveRange(_db.Events); await _db.SaveChangesAsync(); // Act var events = new[] { new Event <string, string>("A", SpecificDate.BeforeChrist(10), SpecificDate.AnnoDomini(12)), new Event <string, string>("B", SpecificDate.BeforeChrist(20, 5)), new Event <string, string>("C", SpecificDate.AnnoDomini(2020, 1, 1), NowDate.Instance), new Event <string, string>("D", NowDate.Instance), new Event <string, string>("E", SpecificDate.BeforeChrist(100, 2, 3, 10), SpecificDate.BeforeChrist(100, 2, 3, 20)), }; await _repo.SaveEventsAsync(events); // Assert var storedEvents = await _db.Events.ToArrayAsync(); storedEvents.ShouldNotBeNull(); storedEvents.Length.ShouldBe(5); var @event = storedEvents.FirstOrDefault(e => e.Content == "A"); @event.ShouldNotBeNull(); @event.StartIsCurrent.ShouldBeFalse(); @event.StartDuration.ShouldNotBeNull(); @event.StartDuration.Value.ShouldBe(Duration.GetDurationFromChristBirth(SpecificDate.BeforeChrist(10))); @event.StartNullPart.ShouldNotBeNull(); @event.StartNullPart.ShouldBe(NullableDateParts.Month); @event.EndIsCurrent.ShouldNotBeNull(); @event.EndIsCurrent.Value.ShouldBeFalse(); @event.EndDuration.ShouldNotBeNull(); @event.EndDuration.Value.ShouldBe(Duration.GetDurationFromChristBirth(SpecificDate.AnnoDomini(12))); @event.EndNullPart.ShouldNotBeNull(); @event.EndNullPart.Value.ShouldBe(NullableDateParts.Month); @event = storedEvents.FirstOrDefault(e => e.Content == "B"); @event.ShouldNotBeNull(); @event.StartIsCurrent.ShouldBeFalse(); @event.StartDuration.ShouldNotBeNull(); @event.StartDuration.Value.ShouldBe(Duration.GetDurationFromChristBirth(SpecificDate.BeforeChrist(20, 5))); @event.StartNullPart.ShouldNotBeNull(); @event.StartNullPart.ShouldBe(NullableDateParts.Day); @event.EndIsCurrent.ShouldBeNull(); @event.EndDuration.ShouldBeNull(); @event.EndNullPart.ShouldBeNull(); @event = storedEvents.FirstOrDefault(e => e.Content == "C"); @event.ShouldNotBeNull(); @event.StartIsCurrent.ShouldBeFalse(); @event.StartDuration.ShouldNotBeNull(); @event.StartDuration.Value.ShouldBe(Duration.GetDurationFromChristBirth(SpecificDate.AnnoDomini(2020, 1, 1))); @event.StartNullPart.ShouldNotBeNull(); @event.StartNullPart.ShouldBe(NullableDateParts.Hour); @event.EndIsCurrent.ShouldNotBeNull(); @event.EndIsCurrent.Value.ShouldBeTrue(); @event.EndDuration.ShouldBeNull(); @event.EndNullPart.ShouldBeNull(); @event = storedEvents.FirstOrDefault(e => e.Content == "D"); @event.ShouldNotBeNull(); @event.StartIsCurrent.ShouldBeTrue(); @event.StartDuration.ShouldBeNull(); @event.StartNullPart.ShouldBeNull(); @event.EndIsCurrent.ShouldBeNull(); @event.EndDuration.ShouldBeNull(); @event.EndNullPart.ShouldBeNull(); @event = storedEvents.FirstOrDefault(e => e.Content == "E"); @event.ShouldNotBeNull(); @event.StartIsCurrent.ShouldBeFalse(); @event.StartDuration.ShouldNotBeNull(); @event.StartDuration.Value.ShouldBe(Duration.GetDurationFromChristBirth(SpecificDate.BeforeChrist(100, 2, 3, 10))); @event.StartNullPart.ShouldNotBeNull(); @event.StartNullPart.ShouldBe(NullableDateParts.Nothing); @event.EndIsCurrent.ShouldNotBeNull(); @event.EndIsCurrent.Value.ShouldBeFalse(); @event.EndDuration.ShouldNotBeNull(); @event.EndDuration.Value.ShouldBe(Duration.GetDurationFromChristBirth(SpecificDate.BeforeChrist(100, 2, 3, 20))); @event.EndNullPart.ShouldNotBeNull(); @event.EndNullPart.Value.ShouldBe(NullableDateParts.Nothing); events.ShouldAllBe(e => e.Id.HasValue); }
public async Task <IActionResult> CreateJob([FromBody] NewJob newJob, Guid teamId, Guid userId, Guid boardId) { Console.WriteLine($"userid {userId} : boardId {boardId}"); var board = await _timelineContext.Boards.FirstOrDefaultAsync(x => x.Id == boardId); var user = await _timelineContext.Users.FirstOrDefaultAsync(x => x.Id == userId); var team = await _timelineContext.Teams.FirstOrDefaultAsync(x => x.Id == teamId); if (board == null || user == null || team == null) { return(BadRequest()); } await _timelineContext.Jobs.AddAsync(newJob.Job); newJob.Job.AssignedMembers = new List <Assignment>(); foreach (var newJobUser in newJob.Users) { newJob.Job.AssignedMembers.Add(new Assignment { JobId = newJob.Job.Id, UserId = newJobUser.Id }); } if (board.Jobs == null) { board.Jobs = new List <Job>(); } if (team.Jobs == null) { team.Jobs = new List <Job>(); } // Assignment assignment = new Assignment {JobId = newJob.Job.Id, UserId = newJob.UserId}; // // if (user.Assignments == null) // { // user.Assignments = new List<Assignment>(); // } // // user.Assignments.Add(assignment); board.Jobs.Add(newJob.Job); team.Jobs.Add(newJob.Job); await _timelineContext.SaveChangesAsync(); return(Ok(newJob.Job)); }