public void Create() { // Arrange var countSets = _sets.Count; var newSet = new SetDTO { PlannedTime = 1800, TimeForRest = 90, }; _mock.Setup(s => s.Create(It.IsAny <SetDTO>())).Returns <SetDTO>(newItem => { newItem.Id = _sets.Count + 1; newItem.CreatedDate = DateTime.Now; newItem.ModifiedDate = DateTime.Now; _sets.Add(newItem); return(newItem.Id); }); // Act var result = _setService.Create(newSet); // Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(IOperationResult)); Assert.AreEqual(countSets + 1, _sets.Count); Assert.IsTrue(result.Succeed); Assert.IsTrue(result.ResultItemId > 0); }
public void Update() { // Arrange var updateSet = new SetDTO { Id = 2, SpentTime = 355 }; _mock.Setup(s => s.Update(It.IsAny <SetDTO>())).Callback <SetDTO>(updateValue => { updateValue.ModifiedDate = DateTime.Now; var setIndex = _sets.FindIndex(set => set.Id == updateValue.Id); _sets[setIndex] = updateValue; }); // Act var result = _setService.Update(updateSet); // Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(IOperationResult)); Assert.IsTrue(result.Succeed); Assert.IsTrue(result.ResultItemId > 0); Assert.AreEqual(_sets.Find(set => set.Id == updateSet.Id).SpentTime, updateSet.SpentTime); }
public SetViewModel(SetDTO Set) { Weight = Set.Weight; Repetitions = Set.Repetitions; Id = Set.Id; IsVisable = Set.Weight != 0 || Set.Repetitions != 0; }
public async Task <SetDTO> AddSetAsync(SetDTO setDTO) { var set = _mapper.Map <Set>(setDTO); set.Order = await _setRepository.GetNextSetOrderOfExerciseAsync(setDTO.ExerciseId); return(_mapper.Map <SetDTO>(await _setRepository.AddAsync(set))); }
private SetViewModel ConvertSetDTO(SetDTO setDTO) { SetViewModel setViewModel = new SetViewModel { RoundID = setDTO.RoundID, SetID = setDTO.SetID, SetOrder = setDTO.SetOrder, Weight = setDTO.Weight }; return(setViewModel); }
public List <SetDTO> GetSetsByGame(int GameID) { List <SetDTO> SetsDTOsByGame = new List <SetDTO>(); SqlConnection StoreConnection = new SqlConnection(); StoreConnection.ConnectionString = "Data Source=.;Initial Catalog=TCGStore;Persist Security Info=True;Integrated Security=true;"; StoreConnection.Open(); SqlCommand GetSetsByGameCommand = new SqlCommand { CommandText = "GetSetsByGameID", CommandType = CommandType.StoredProcedure, Connection = StoreConnection }; SqlParameter GameIDParameter = new SqlParameter { ParameterName = "GameID", Direction = ParameterDirection.Input, SqlDbType = SqlDbType.VarChar, SqlValue = GameID }; GetSetsByGameCommand.Parameters.Add(GameIDParameter); SqlDataReader DataReader; DataReader = GetSetsByGameCommand.ExecuteReader(); if (DataReader.HasRows) { while (DataReader.Read()) { SetDTO FoundSet = new SetDTO(); for (int index = 0; index < DataReader.FieldCount; index++) { FoundSet.SetID = int.Parse(DataReader["SetID"].ToString()); FoundSet.GameID = int.Parse(DataReader["GameID"].ToString()); FoundSet.SetCode = DataReader["SetCode"].ToString(); FoundSet.SetName = DataReader["SetName"].ToString(); } SetsDTOsByGame.Add(FoundSet); } } DataReader.Close(); StoreConnection.Close(); return(SetsDTOsByGame); }
public List <SetDTO> GetAllSets() { List <SetDTO> SetDTOs = new List <SetDTO>(); SqlConnection StoreConnection = new SqlConnection(); StoreConnection.ConnectionString = "Data Source=.;Initial Catalog=TCGStore;Persist Security Info=True;Integrated Security=true;"; StoreConnection.Open(); SqlCommand GetAllSetsCommand = new SqlCommand { CommandText = "GetAllSets", CommandType = CommandType.StoredProcedure, Connection = StoreConnection }; SqlDataReader DataReader; DataReader = GetAllSetsCommand.ExecuteReader(); if (DataReader.HasRows) { while (DataReader.Read()) { SetDTO FoundSet = new SetDTO(); for (int index = 0; index < DataReader.FieldCount; index++) { FoundSet.SetID = int.Parse(DataReader[index].ToString()); FoundSet.GameID = int.Parse(DataReader[index].ToString()); FoundSet.SetCode = DataReader[index].ToString(); FoundSet.SetName = DataReader[index].ToString(); } SetDTOs.Add(FoundSet); } } DataReader.Close(); StoreConnection.Close(); return(SetDTOs); }
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); }
private SetDTO ConvertSet(Set set) { SetDTO setDTO = new SetDTO(set.Weight, set.SetID, set.SetOrder, set.RoundID); return(setDTO); }
private Set ConvertSetDTO(SetDTO setDTO) { Set set = new Set(setDTO.Weight, setDTO.SetOrder, setDTO.SetID, setDTO.RoundID); return(set); }
private SetDTO ConvertSetVM(SetViewModel setViewModel) { SetDTO set = new SetDTO(setViewModel.Weight, setViewModel.SetOrder); return(set); }
public async Task <IActionResult> Post([FromBody] SetDTO setDTO) { var result = await _setService.AddSetAsync(setDTO); return(Ok(result)); }
static void Main(string[] args) { WorkOutContext context = new WorkOutContext("WorkOutDbConnection"); WorkOutContext context1 = new WorkOutContext("WorkOutDbConnection"); Repository <Set> repSet = new Repository <Set>(context); Repository <Exercise> repExercise = new Repository <Exercise>(context); Repository <Approach> repApproach = new Repository <Approach>(context); Repository <Training> repTraining = new Repository <Training>(context); //var set = context.Sets.FirstOrDefault(); TrainingType tt2 = context.TrainingTypes.FirstOrDefault(); var trainingType1 = context.TrainingTypes.FirstOrDefault <TrainingType>(); trainingType1.TypeTraining = "База 1"; var ttEntry = context.Entry <TrainingType>(trainingType1); var trainingCol = ttEntry.Collection <Training>("Trainings"); ttEntry.Reload(); var training = context.Trainings.Where(tr => tr.Id == 2).FirstOrDefault(); context.Trainings.Remove(training); //set.Training = training; //context.SaveChanges(); ExerciseDTO firstEx = new ExerciseDTO { Name = "Test", CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now }; SetDTO set1 = new SetDTO { TimeForRest = 10, PlannedTime = 0, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now }; DTOSetRepository dtoSetRepository = null; DTORepository <Approach, ApproachDTO> dtoApproachRepository = new DTORepository <Approach, ApproachDTO>(null); DTORepository <Exercise, ExerciseDTO> dtoExcerciseRepository = new DTORepository <Exercise, ExerciseDTO>(null); firstEx.Id = dtoExcerciseRepository.Create(firstEx); firstEx.CreatedDate = DateTime.Now; firstEx.ModifiedDate = DateTime.Now; set1.Exercises.Add(firstEx); dtoSetRepository.Create(set1); string settttt = "Set"; var exer = context.Exercises.Include(settttt).Where(item => item.Id == 1).FirstOrDefault(); ApproachDTO approachDTO = new ApproachDTO { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, PlannedTimeForRest = 10, SpentTimeForRest = 12 }; var approaches = dtoApproachRepository.GetAll(); //context1.Exercises.Attach(ex); //var contextChanges = context1.ChangeTracker.Entries().ToList(); //repSet.Create(set1); //Exercise firstEx = new Exercise //{ // Name = "Test", // CreatedDate = DateTime.Now, // ModifiedDate = DateTime.Now //}; //Approach firstApproach = new Approach //{ // PlannedTimeForRest = 0, // SpentTimeForRest = 0, // CreatedDate = DateTime.Now, // ModifiedDate = DateTime.Now //}; //repApproach.Create(firstApproach); //Set set = new Set //{ // TimeForRest = 10, // PlannedTime = 0, // CreatedDate = DateTime.Now, // ModifiedDate = DateTime.Now //}; //set.Approaches.Add(firstApproach); //set.Exercises.Add(firstEx); //repSet.Create(set); Repository <TrainingType> rep = new Repository <TrainingType>(context); //var test = rep.Get(1); TrainingType test1 = new TrainingType { Id = 1, TypeTraining = "Op", Description = "aaa", CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now }; foreach (var changeTrack in context.ChangeTracker.Entries()) { Console.WriteLine(changeTrack.Entity); } context.Set <TrainingType>().Attach(test1); foreach (var changeTrack in context.ChangeTracker.Entries()) { Console.WriteLine(changeTrack.Entity); } rep.Update(test1); var tt = new TrainingType { Description = "test 4", TypeTraining = "TT 4", CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now }; rep.Create(tt); Repository <TrainingType> rep1 = new Repository <TrainingType>(context); var trainingType = rep1.Get(tt.Id); trainingType.TypeTraining = "fwefwef"; trainingType.Trainings = new List <Training>(); rep1.Update(tt); }
public int AddNonExistingSetsToDataBase(SetDTO NewSet) { int SetIDToPass; SqlConnection StoreConnection = new SqlConnection(); StoreConnection.ConnectionString = "Data Source=.;Initial Catalog=TCGStore;Persist Security Info=True;Integrated Security=true;"; StoreConnection.Open(); SqlCommand AddNewSet = new SqlCommand { CommandText = "InsertIntoSet", CommandType = CommandType.StoredProcedure, Connection = StoreConnection }; SqlParameter GameIDParameter = new SqlParameter { ParameterName = "GameID", Direction = ParameterDirection.Input, SqlDbType = SqlDbType.Int, SqlValue = NewSet.GameID }; AddNewSet.Parameters.Add(GameIDParameter); SqlParameter SetCodeParameter = new SqlParameter { ParameterName = "SetCode", Direction = ParameterDirection.Input, SqlDbType = SqlDbType.VarChar, SqlValue = NewSet.SetCode }; AddNewSet.Parameters.Add(SetCodeParameter); SqlParameter SetNameParameter = new SqlParameter { ParameterName = "SetName", Direction = ParameterDirection.Input, SqlDbType = SqlDbType.VarChar, SqlValue = NewSet.SetName }; AddNewSet.Parameters.Add(SetNameParameter); SqlParameter ReleaseDateParameter = new SqlParameter { ParameterName = "ReleaseDate", Direction = ParameterDirection.Input, SqlDbType = SqlDbType.VarChar, SqlValue = NewSet.ReleaseDate }; AddNewSet.Parameters.Add(ReleaseDateParameter); SetIDToPass = Convert.ToInt32(AddNewSet.ExecuteScalar().ToString()); StoreConnection.Close(); return(SetIDToPass); }
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); } } }
public async Task <bool> PostNewSets(int GameID) { bool Success; SetDataController SetDataController = new SetDataController(); List <YgoSetAPIResponse> YgoSetResponse = new List <YgoSetAPIResponse>(); PokemonSetAPIResponseRoot PokemonSetResponse = new PokemonSetAPIResponseRoot(); List <SetDTO> NonExistingSets = new List <SetDTO>(); List <SetDTO> ExistingSets = new List <SetDTO>(); GamesDataController GameDataController = new GamesDataController(); GameDTO GameDTO = GameDataController.GetGameByID(GameID); CardController CardController = new CardController(); using (var HttpClient = new HttpClient()) { switch (GameDTO.GameName) { case "Yu-Gi-Oh": using (var Response = await HttpClient.GetAsync("https://db.ygoprodeck.com/api/v7/cardsets.php")) { string ApiResponse = await Response.Content.ReadAsStringAsync(); YgoSetResponse = JsonConvert.DeserializeObject <List <YgoSetAPIResponse> >(ApiResponse); } foreach (var Item in YgoSetResponse) { SetDTO NewSet = new SetDTO(); NewSet.GameID = GameID; NewSet.SetCode = Item.set_code; NewSet.SetName = Item.set_name; NewSet.ReleaseDate = Item.tcg_date; NonExistingSets.Add(NewSet); } break; case "Pokemon": using (var Response = await HttpClient.GetAsync("https://api.pokemontcg.io/v1/sets")) { string ApiResponse = await Response.Content.ReadAsStringAsync(); PokemonSetResponse = JsonConvert.DeserializeObject <PokemonSetAPIResponseRoot>(ApiResponse); } foreach (var Item in PokemonSetResponse.sets) { SetDTO NewSet = new SetDTO(); NewSet.GameID = GameID; NewSet.SetCode = Item.code; NewSet.SetName = Item.name; NewSet.ReleaseDate = Item.releaseDate; NonExistingSets.Add(NewSet); } break; } } ExistingSets = SetDataController.GetSetsByGame(GameID); HashSet <string> SetCodes = new HashSet <string>(ExistingSets.Select(x => x.SetCode)); NonExistingSets.RemoveAll(x => SetCodes.Contains(x.SetCode)); if (NonExistingSets.Count == 0 || NonExistingSets == null) { Success = false; } else { int SetID; foreach (var Set in NonExistingSets) { SetID = SetDataController.AddNonExistingSetsToDataBase(Set); switch (GameDTO.GameName) { case "Yu-Gi-Oh": await CardController.AddYugiohCards(SetID, Set.SetName, Set.SetCode); break; case "Pokemon": await CardController.AddPokemonCards(SetID, Set.SetCode); break; } } Success = true; } return(Success); }