public async Task <IActionResult> Create(Person person) { if (ModelState.IsValid) { _context.Person.Add(person); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(person)); }
public async Task <Session> AddOrUpdate(Session session) { await _dbContext.Sessions.AddAsync(session); await _dbContext.SaveChangesAsync(); return(session); }
public async Task <Unit> Handle(CreateLocationCommand request, CancellationToken cancellationToken) { dbContext.TrackPoints.Add(new TrackPoint { UserId = request.UserId, Latitude = request.Latitude, Longitude = request.Longitude, Heading = request.Heading, Speed = request.Speed, Timestamp = request.Timestamp }); await dbContext.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <ExerciseType> Add(string name) { if (Get().Any(e => e.Name.ToLower() == name.ToLower())) { throw new InvalidOperationException("Exercise Already Exists"); } ExerciseType exerciseType = new ExerciseType() { Name = name }; await _dbContext.ExerciseTypes.AddAsync(exerciseType); await _dbContext.SaveChangesAsync(); return(exerciseType); }
public static async Task SeedSampleDataAsync(TrackerDbContext context) { // seed predefined data. if (!context.Projects.Any()) { // predefined project. var project = context.Projects.Add(new Project { Key = "TRCK", Name = "Tracker System", OwnerId = "*****@*****.**" }); // add creator/owner as a default participant. context.ProjectParticipants.Add(new ProjectParticipant { AddedBy = "*****@*****.**", ProjectId = project.Entity.Id, UserId = "*****@*****.**" }); // add new issue. context.Issues.Add(new Issue { Id = $"{project.Entity.Key}-{1}", ProjectId = project.Entity.Id, Description = "User Story for Tracker Sysytem Project description", Reporter = "*****@*****.**", Status = Domain.Enums.IssueStatus.Todo, StoryPoint = 8, Title = "User Story for Tracker Sysytem Project", Type = Domain.Enums.IssueType.Story }); await context.SaveChangesAsync(); } }