public List <RoundDTO> GetRounds(string trainingID) { using (SqlConnection connection = new SqlConnection(GetConnectionString())) { List <RoundDTO> rounds = new List <RoundDTO>(); SqlCommand cmd = new SqlCommand("SELECT * FROM Rounds WHERE TrainingID = @TrainingID", connection); cmd.Parameters.AddWithValue("@TrainingID", trainingID); connection.Open(); Guid exerciseID = Guid.Empty; ExerciseDTO exercise = new ExerciseDTO(); Guid roundID = Guid.Empty; using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { exerciseID = Guid.Parse(reader["ExerciseID"].ToString()); exercise = GetExerciseDTO(exerciseID.ToString()); roundID = Guid.Parse(reader["ID"].ToString()); RoundDTO round = new RoundDTO(exercise, roundID, Guid.Parse(trainingID), exerciseID, null); rounds.Add(round); } return(rounds); } } }
public async void ReturnRoundWhichExistsInDbByGivenId() { // Assert var round = new Round() { Id = 1, Name = "Round 1" }; RoundDTO testRound = null; _repositoryMock.Reset(); _repositoryMock.Setup(r => r.GetByIdAsync(It.IsAny <uint>())).ThrowsAsync(new ArgumentException()); _repositoryMock.Setup(r => r.GetByIdAsync(1)).ReturnsAsync(round); var expectedRound = _mapper.Map <RoundDTO>(round); // Act var err = await Record.ExceptionAsync(async () => testRound = await _service.GetByIdAsync(1)); // Arrange err.Should().BeNull(); testRound.Should().NotBeNull(); testRound.Should().BeEquivalentTo(expectedRound); }
public ActionResult AddRound(RoundDTO roundDto) { using (var db = new GunStoreContext()) { if (ModelState.IsValid) { var round = new Round() { Name = roundDto.Name, Description = roundDto.Description, Price = roundDto.Price, Quantity = roundDto.Quantity, Caliber = roundDto.Caliber }; if (roundDto.Image != null) { round.Image = new byte[roundDto.Image.ContentLength]; roundDto.Image.InputStream.Read(round.Image, 0, roundDto.Image.ContentLength); } db.Rounds.Add(round); db.SaveChanges(); ModelState.Clear(); return(RedirectToAction("AddProduct", "Admin")); } ModelState.AddModelError("round", "Invalid round added"); return(View()); } }
public int Save(RoundDTO obj, string currentUserId) { Round round; try { _unitOfWork.BeginTransaction(); if (obj.Id == 0) { round = new Round(); Mapper.Map <RoundDTO, Round>(obj, round); round.CreateDate = DateTime.Now; round.CreatedBy = currentUserId; base.Insert(round); } else { round = _repository.Find(obj.Id); Mapper.Map <RoundDTO, Round>(obj, round); round.LastUpdateDate = DateTime.Now; round.LastUpdateBy = currentUserId; base.Update(round); } _unitOfWork.SaveChanges(); _unitOfWork.Commit(); return(round.Id); } catch (Exception) { throw; } }
/// <summary> /// Initializes a new instance of the <see cref="RoundCI"/> class /// </summary> /// <param name="dto">The <see cref="RoundDTO"/> used to create new instance</param> /// <param name="culture">The culture of the input <see cref="RoundDTO"/></param> internal RoundCI(RoundDTO dto, CultureInfo culture) { Guard.Argument(dto, nameof(dto)).NotNull(); Guard.Argument(culture, nameof(culture)).NotNull(); _names = new Dictionary <CultureInfo, string>(); _phaseOrGroupLongName = new Dictionary <CultureInfo, string>(); Merge(dto, culture); }
private static void ValidateMatchRound(matchRound msg, RoundDTO dto) { Assert.AreEqual(msg.name, dto.Name); Assert.AreEqual(msg.name, dto.Name); Assert.AreEqual(msg.cup_round_match_number, dto.CupRoundMatchNumber); Assert.AreEqual(msg.cup_round_matches, dto.CupRoundMatches); Assert.AreEqual(msg.number, dto.Number); Assert.AreEqual(msg.type, dto.Type); }
private static void CompareRound(RoundDTO round, XElement element) { Assert.IsNotNull(round); Assert.IsNotNull(element); Assert.AreEqual(round.Type, element.Attribute("type")?.Value); var number = element.Attribute("number")?.Value; Assert.AreEqual(round.Number, number == null ? (int?)null : int.Parse(number)); }
/// <summary> /// Initializes a new instance of the <see cref="RoundCI"/> class /// </summary> /// <param name="dto">The <see cref="RoundDTO"/> used to create new instance</param> /// <param name="culture">The culture of the input <see cref="RoundDTO"/></param> internal RoundCI(RoundDTO dto, CultureInfo culture) { Contract.Requires(dto != null); Contract.Requires(culture != null); Contract.Ensures(_names != null); Contract.Ensures(_phaseOrGroupLongName != null); _names = new Dictionary <CultureInfo, string>(); _phaseOrGroupLongName = new Dictionary <CultureInfo, string>(); Merge(dto, culture); }
private RoundDTO ConvertRoundVM(RoundViewModel roundViewModel) { List <SetDTO> sets = new List <SetDTO>(); foreach (var set in roundViewModel.Sets) { set.SetOrder = roundViewModel.Sets.IndexOf(set); sets.Add(ConvertSetVM(set)); } UserCollection userCollection = new UserCollection(); ExerciseDTO exercise = userCollection.GetExercise(roundViewModel.Exercise.Name); RoundDTO round = new RoundDTO(exercise, exercise.ExerciseID, sets); return(round); }
/// <summary> /// Merges the specified <see cref="RoundDTO"/> into instance /// </summary> /// <param name="dto">The <see cref="RoundDTO"/> used fro merging</param> /// <param name="culture">The culture of the input <see cref="RoundDTO"/></param> internal void Merge(RoundDTO dto, CultureInfo culture) { Guard.Argument(dto, nameof(dto)).NotNull(); Type = dto.Type; Group = dto.Group; GroupId = dto.GroupId; OtherMatchId = dto.OtherMatchId; Number = dto.Number; CupRoundMatches = dto.CupRoundMatches; CupRoundMatchNumber = dto.CupRoundMatchNumber; BetradarId = dto.BetradarId; _names[culture] = dto.Name; _phaseOrGroupLongName[culture] = dto.PhaseOrGroupLongName; Phase = dto.Phase; }
public RoundDTO GetById(int roundId) { try { RoundDTO round = new RoundDTO(); Mapper.Map <Round, RoundDTO>(_repository .Query() .SelectQueryable() .Where(c => c.Id == roundId).FirstOrDefault(), round); return(round); } catch (Exception ex) { throw ex; } }
/// <summary> /// Merges the specified <see cref="RoundDTO"/> into instance /// </summary> /// <param name="dto">The <see cref="RoundDTO"/> used fro merging</param> /// <param name="culture">The culture of the input <see cref="RoundDTO"/></param> internal void Merge(RoundDTO dto, CultureInfo culture) { Contract.Requires(dto != null); Type = dto.Type; Group = dto.Group; GroupId = dto.GroupId; OtherMatchId = dto.OtherMatchId; Number = dto.Number; CupRoundMatches = dto.CupRoundMatches; CupRoundMatchNumber = dto.CupRoundMatchNumber; BetradarId = dto.BetradarId; _names[culture] = dto.Name; _phaseOrGroupLongName[culture] = dto.PhaseOrGroupLongName; Phase = dto.Phase; }
public async void ReturnNullWhenRoundDoNotExistsInDbByGivenId() { // Assert RoundDTO testRound = null; _repositoryMock.Reset(); _repositoryMock.Setup(r => r.GetByIdAsync(It.IsAny <uint>())).ReturnsAsync((Round)null); // Act var err = await Record.ExceptionAsync(async () => testRound = await _service.GetByIdAsync(1)); // Arrange err.Should().BeNull(); testRound.Should().BeNull(); }
private RoundDTO ConvertRound(Round round) { List <SetDTO> setDTOs = new List <SetDTO>(); foreach (var set in round.GetSets()) { setDTOs.Add(ConvertSet(set)); } IExerciseDAL dal = ExerciseDALFactory.GetExerciseDAL(); RoundDTO roundDTO = new RoundDTO( dal.GetExerciseDTO(round.ExerciseID.ToString()), round.RoundID, round.TrainingID, round.ExerciseID, setDTOs); return(roundDTO); }
private Round ConvertRoundDTO(RoundDTO roundDTO) { List <Set> sets = new List <Set>(); foreach (var setDTO in roundDTO.GetSets()) { sets.Add(ConvertSetDTO(setDTO)); } IExerciseDAL dal = ExerciseDALFactory.GetExerciseDAL(); Round round = new Round( ConvertExerciseDTO(dal.GetExerciseDTO(roundDTO.ExerciseID.ToString())), sets, roundDTO.RoundID, roundDTO.TrainingID, roundDTO.ExerciseID ); return(round); }
private Round ConvertRoundDTO(RoundDTO roundDTO) { List <Set> sets = new List <Set>(); foreach (var setDTO in roundDTO.GetSets()) { sets.Add(ConvertSetDTO(setDTO)); } User user = new User(); Round round = new Round( ConvertExerciseDTO(user.GetExercise(roundDTO.ExerciseID.ToString())), sets, roundDTO.RoundID, roundDTO.TrainingID, roundDTO.ExerciseID ); return(round); }
private RoundViewModel ConvertRoundDTO(RoundDTO roundDTO) { List <SetViewModel> setViewModels = new List <SetViewModel>(); foreach (var setDTO in roundDTO.GetSets()) { setViewModels.Add(ConvertSetDTO(setDTO)); } ; RoundViewModel roundViewModel = new RoundViewModel { Exercise = ConvertExerciseDTOToVM(roundDTO.Exercise), ExerciseID = roundDTO.ExerciseID, RoundID = roundDTO.RoundID, TrainingID = roundDTO.TrainingID, Sets = setViewModels }; return(roundViewModel); }
public async void GetRoundByIdOk(int id) { // Arrange RoundDTO returnedRound = null; // Act var response = await _client.GetAsync($"api/rounds/{id}"); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); var deserializeErr = Record.Exception(() => returnedRound = JsonConvert.DeserializeObject <RoundDTO>(responseString)); // Assert Assert.Null(deserializeErr); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotNull(returnedRound); }
public void RoundMergeTest() { var matchRoundTypeEn = new matchRound { name = "round name in english", cup_round_match_number = 1, cup_round_match_numberSpecified = true, cup_round_matches = 2, cup_round_matchesSpecified = true, number = 10, numberSpecified = true, type = "match type 1", }; var matchRoundTypeDe = new matchRound { name = "round name in deutsch", cup_round_match_number = 1, cup_round_match_numberSpecified = true, cup_round_matches = 2, cup_round_matchesSpecified = true, number = 10, numberSpecified = true, type = "match type 1", }; var roundDTO1 = new RoundDTO(matchRoundTypeEn); var roundDTO2 = new RoundDTO(matchRoundTypeDe); var roundCI = new RoundCI(roundDTO1, _cultureFirst); roundCI.Merge(roundDTO2, _cultureSecond); Assert.IsNotNull(roundCI); Assert.AreEqual(matchRoundTypeEn.name, roundCI.GetName(_cultureFirst)); Assert.AreEqual(matchRoundTypeDe.name, roundCI.GetName(_cultureSecond)); Assert.AreEqual(matchRoundTypeEn.cup_round_match_number, roundCI.CupRoundMatchNumber); Assert.AreEqual(matchRoundTypeEn.cup_round_matches, roundCI.CupRoundMatches); Assert.AreEqual(matchRoundTypeEn.number, roundCI.Number); Assert.AreEqual(matchRoundTypeEn.type, roundCI.Type); }
public void AddStrengthTraining(WeightTrainingDTO training) { ITrainingDAL dal = TrainingDALFactory.GetTrainingDAL(); Guid trainingID = Guid.NewGuid(); List <RoundDTO> rounds = new List <RoundDTO>(); foreach (var round in training.GetRounds()) { Guid roundID = Guid.NewGuid(); List <SetDTO> sets = new List <SetDTO>(); foreach (var set in round.GetSets()) { SetDTO setToAdd = new SetDTO(set.Weight, Guid.NewGuid(), set.SetOrder, roundID); sets.Add(setToAdd); } RoundDTO roundToAdd = new RoundDTO(round.Exercise, roundID, trainingID, round.ExerciseID, sets); rounds.Add(roundToAdd); } WeightTrainingDTO weightTrainingToAdd = new WeightTrainingDTO(rounds, trainingID, training.UserID, training.Date, training.TrainingType); dal.AddWeightTraining(weightTrainingToAdd); }
public WeightTrainingDTO GetWeightTraining(string trainingID) { using (SqlConnection connection = new SqlConnection(GetConnectionString())) { SqlCommand cmdTraining = new SqlCommand("SELECT * FROM Trainings WHERE ID = @TrainingID", connection); cmdTraining.Parameters.AddWithValue("@TrainingID", trainingID); DateTime date = DateTime.MinValue; Guid userID = Guid.Empty; TrainingTypeDTO trainingType = TrainingTypeDTO.Strength; connection.Open(); using (SqlDataReader reader = cmdTraining.ExecuteReader()) { while (reader.Read()) { date = Convert.ToDateTime(reader["Date"]); userID = Guid.Parse(reader["UserID"].ToString()); trainingType = (TrainingTypeDTO)Enum.Parse(typeof(TrainingTypeDTO), reader["TrainingType"].ToString()); } } connection.Close(); SqlCommand cmdRound = new SqlCommand("SELECT * FROM Rounds WHERE TrainingID = @TrainingID", connection); cmdRound.Parameters.AddWithValue("@TrainingID", trainingID); List <RoundDTO> rounds = new List <RoundDTO>(); connection.Open(); using (SqlDataReader reader = cmdRound.ExecuteReader()) { while (reader.Read()) { Guid exerciseID = Guid.Parse(reader["ExerciseID"].ToString()); ExerciseDTO exercise = GetExerciseDTO(exerciseID.ToString()); Guid roundID = Guid.Parse(reader["ID"].ToString()); SqlCommand cmdSet = new SqlCommand("SELECT * FROM Sets WHERE RoundID = @RoundID ORDER BY SetOrder", connection); cmdSet.Parameters.AddWithValue("@RoundID", roundID); List <SetDTO> sets = new List <SetDTO>(); using (SqlDataReader setReader = cmdSet.ExecuteReader()) { while (setReader.Read()) { Guid setID = Guid.Parse(setReader["SetID"].ToString()); int setOrder = Convert.ToInt32(setReader["SetOrder"]); double weight = Convert.ToInt32(setReader["Weight"]); SetDTO setDTO = new SetDTO(weight, setID, setOrder, roundID); sets.Add(setDTO); } } RoundDTO roundDTO = new RoundDTO(exercise, roundID, Guid.Parse(trainingID), exerciseID, sets); rounds.Add(roundDTO); } WeightTrainingDTO weightTrainingDTO = new WeightTrainingDTO(rounds, Guid.Parse(trainingID), userID, date, trainingType); return(weightTrainingDTO); } } }