public static DataBaseContext CreateWithData() { var options = new DbContextOptionsBuilder <DataBaseContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var context = new DataBaseContext(options); context.Database.EnsureCreated(); var coachEmail = Email.Create("*****@*****.**"); var coach = Coach.Create("DbContextFactorylogin", "DbContextFactorypassword", "DbContextFactoryfirstName", "DbContextFactorylastName", "Qwertyqwerty", coachEmail); var runnerEmail = Email.Create("*****@*****.**"); var runner = Runner.Create("DbContextFactoryrunnerName", "DbContextFactoryrunnerLastName", runnerEmail); var trainingDetails = TraningDetails.Create("details", "comment"); var training = Training.Create(DateTime.UtcNow, trainingDetails); coach.AddRunner(runner); coach.AddTrainigForRunner(runner, training); context.Add(coach); context.Runners.Add(runner); context.Traings.Add(training); context.SaveChanges(); return(context); }
public async Task <bool> Add(TrainingForAddDto trainingForAddDto, int userId) { var user = await _repoUser.GetUser(userId); var trainingToCreate = Training.Create(trainingForAddDto.Name.Trim(), trainingForAddDto.Date, user); foreach (var trainingExerciseDto in trainingForAddDto.Exercises) { var exercise = await _repoExercise.GetByName(trainingExerciseDto.Exercise.Name, user.Id); if (exercise == null) { _repoExercise.Add(Exercise.Create(trainingExerciseDto.Exercise.Name, user)); await _repoExercise.SaveAll(); exercise = await _repoExercise.GetByName(trainingExerciseDto.Exercise.Name, user.Id); } var exerciseToCreate = TrainingExercise.Create(exercise, user); foreach (var set in trainingExerciseDto.Sets) { var unit = await _repoUnit.GetByCode(set.Unit); var setToCreate = TrainingExerciseSet.Create(set.Reps, set.Weight, unit, user); exerciseToCreate.Sets.Add(setToCreate); } trainingToCreate.Exercises.Add(exerciseToCreate); } _repoTraining.Add(trainingToCreate); return(await _repoTraining.SaveAll()); }
private async Task <Training> CreateTraining(DataContext context, User user) { var training = Training.Create( "Training 1", new DateTime(2020, 7, 20), user ); var exercise = await GetExercise(context); var trainingExercise = TrainingExercise.Create(exercise, user); var unit = await GetUnit(context); var trainingExerciseSet1 = TrainingExerciseSet.Create( 10, 80, unit, user ); var trainingExerciseSet2 = TrainingExerciseSet.Create( 10, 85, unit, user ); trainingExercise.Sets.Add(trainingExerciseSet1); trainingExercise.Sets.Add(trainingExerciseSet2); training.Exercises.Add(trainingExercise); return(training); }
public ActionResult Create(FormCollection form) { JObject json = new JObject(); json["error"] = false; json["message"] = ""; string[] keys = new string[] { "desc", "faci", "title", "loc", "start-month", "start-day", "start-year", "end-month", "end-day", "end-year" }; if (this.HasValues(form, keys)) { // check if the logged in user is the HR Head if (!this.CheckLogin(AccountType.Applicant)) { if (((Employee)this.GetAccount().Profile).Department.Type == DepartmentType.HumanResources) { try { Training tr = new Training(); tr.Description = form.GetValue("desc").AttemptedValue; tr.Facilitator = form.GetValue("faci").AttemptedValue; tr.Title = form.GetValue("title").AttemptedValue; tr.Location = form.GetValue("loc").AttemptedValue; string start = (Int32.Parse(form.GetValue("start-month").AttemptedValue) + 1).ToString("00") + "/" + (Int32.Parse(form.GetValue("start-day").AttemptedValue) + 1).ToString("00") + "/" + form.GetValue("start-year").AttemptedValue; string end = (Int32.Parse(form.GetValue("end-month").AttemptedValue) + 1).ToString("00") + "/" + (Int32.Parse(form.GetValue("end-day").AttemptedValue) + 1).ToString( "00") + "/" + form.GetValue("end-year").AttemptedValue; tr.StartDate = DateTime.ParseExact(start, "MM/dd/yyyy", CultureInfo.InvariantCulture); tr.EndDate = DateTime.ParseExact(end, "MM/dd/yyyy", CultureInfo.InvariantCulture); tr.Create(); } catch (Exception e) { json["error"] = true; json["message"] = e.Message; } } } else // else return an error { json["error"] = true; json["message"] = "You are not authorized to continue"; } } else { json["error"] = true; json["message"] = "Form is incomplete"; } return(Content(json.ToString(), "application/json")); }
public async Task HandleAsync(CreateTrainingCommand command, CancellationToken cancellationToken = default) { Guid.TryParse(httpContext.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value, out Guid coachId); var coach = await repository.GetByAsync(p => p.Id == coachId, new[] { "Runners" }, cancellationToken); if (coach.Runners.Capacity == 0) { throw new ArgumentNullException("Coach does not have this runner!"); } var runner = coach.Runners.Find(r => r.Id == command.RunnerId); if (runner == null) { throw new ArgumentNullException("Coach does not have this runner!"); } var trainingDetails = TraningDetails.Create(command.Details, command.Comments); var training = Training.Create(command.TimeToDo, trainingDetails); coach.AddTrainigForRunner(runner, training); var coachName = $"{coach.FirstName} {coach.LastName}"; await eventPublisher.PublishAsync <TrainingCreated> (new TrainingCreated(training.Id, DateTime.Now, coachName, runner.Email.EmailAdress)); await repository.SaveAsync(coach); }
private static void CreateTraining(JArray trainingsData) { foreach (JObject training in trainingsData) { var info = GetAreaExtendedInfo(training); Training.Create(info); } }
public Training Execute(string name, int seats, int color) { if (_queries.GetTrainingId(name).HasValue) { throw new TrainingAlreadyExistsException(name); } var formation = Training.Create(name, seats, color); PublishUncommitedEvents(formation); return(formation); }
public void throw_error_if_training_name_null_or_empty(string trainingName) { Action action = () => Training.Create(trainingName, 1, Color.Empty.ToArgb()); action.ShouldThrow <TrainingEmptyNameException>(); }
public void raise_trainingCreated_on_create_new_training() { var training = Training.Create("TED", 1, Color.Empty.ToArgb()); training.UncommitedEvents.GetStream().Should().Contain(new TrainingCreated(Guid.Empty, 1, "TED", 1, Color.Empty.ToArgb())); }