//Get Trainee Details public static bool GetTraineeExistById(string id) { ComputerGymDBContext db = new ComputerGymDBContext(); TraineeDetailsDto trainee = db.Trainees.Select(x => new TraineeDetailsDto() { id = x.Trainee_Id, f_name = x.First_Name, l_name = x.Last_Name, user_name = x.User_Name, password = x.Password, phone_number = x.Phone_Number, date_Of_birth = x.Date_Of_Birth, height = x.Height, weight = x.Weight, gender = x.Gender, address = x.Address, Amount_Of_Training_Per_Week = x.Amount_Of_Training_Per_Week, Perform_Exercises = x.Perform_Exercises, Training_Goal = x.Training_Goal, Fitness_Level = x.Fitness_Level, Body_Problem = x.Body_Problem }).SingleOrDefault(x => x.id == id); if (trainee == null) { return(false); } return(true); }
//POST Trainee Details public static bool AddTrainee(Trainee traineeDetails) { ComputerGymDBContext db = new ComputerGymDBContext(); Trainee trainee = new Trainee(); trainee.Trainee_Id = traineeDetails.Trainee_Id; trainee.First_Name = traineeDetails.First_Name; trainee.Last_Name = traineeDetails.Last_Name; trainee.User_Name = traineeDetails.User_Name; trainee.Password = traineeDetails.Password; trainee.Phone_Number = traineeDetails.Phone_Number; trainee.Date_Of_Birth = traineeDetails.Date_Of_Birth; trainee.Height = traineeDetails.Height; trainee.Weight = traineeDetails.Weight; trainee.Gender = traineeDetails.Gender; trainee.Address = traineeDetails.Address; trainee.Amount_Of_Training_Per_Week = traineeDetails.Amount_Of_Training_Per_Week; trainee.Perform_Exercises = traineeDetails.Perform_Exercises; trainee.Training_Goal = traineeDetails.Training_Goal; trainee.Fitness_Level = traineeDetails.Fitness_Level; trainee.Body_Problem = traineeDetails.Body_Problem; try { db.Trainees.Add(trainee); db.SaveChanges(); } catch { return(false); } return(true); }
//מתודה לעידכון פרטים של מאמן public static bool UpdateTrainer(Trainer trainer) { ComputerGymDBContext db = new ComputerGymDBContext(); Trainer trainerToUpdate = db.Trainers.SingleOrDefault(x => x.Trainer_Id == trainer.Trainer_Id); if (trainerToUpdate == null) { return(false); } else if (trainerToUpdate != null) { trainerToUpdate.First_Name = trainer.First_Name; trainerToUpdate.Last_Name = trainer.Last_Name; trainerToUpdate.User_Name = trainer.User_Name; trainerToUpdate.Password = trainer.Password; trainerToUpdate.Phone_Number = trainer.Phone_Number; try { db.SaveChanges(); return(true); } catch (Exception) { return(false); } } return(false); }
//מתודה לעדכון מתקן public static bool UpdateGymFacility(Gym_Facility gym_facility) { ComputerGymDBContext db = new ComputerGymDBContext(); Gym_Facility gymFacility = db.Gym_Facility.SingleOrDefault(x => x.Facility_Code == gym_facility.Facility_Code); if (gymFacility == null) { return(false); } else if (gymFacility != null) { gymFacility.Category = gym_facility.Category; gymFacility.Facility_Name = gym_facility.Facility_Name; gymFacility.Picture = gym_facility.Picture; gymFacility.Big_Muscle = gym_facility.Big_Muscle; try { db.SaveChanges(); return(true); } catch (Exception) { return(false); } } return(false); }
//מתודה לעדכון קישור למתקן public static bool UpdateFacilityVideoLink(Facility_Video_Link facility_video_link) { ComputerGymDBContext db = new ComputerGymDBContext(); Facility_Video_Link facilityVideoLink = db.Facility_Video_Link.SingleOrDefault(x => x.Video_Link_Code == facility_video_link.Video_Link_Code); if (facilityVideoLink == null) { return(false); } else if (facilityVideoLink != null) { facilityVideoLink.Video_Link = facility_video_link.Video_Link; try { db.SaveChanges(); return(true); } catch (Exception) { return(false); } } return(false); }
//Put Trainee Program public static bool UpdateTraineeProgram(Trainer_Facility_Recommendation update_program) { ComputerGymDBContext db = new ComputerGymDBContext(); Trainer_Facility_Recommendation up_program = db.Trainer_Facility_Recommendation.SingleOrDefault(x => x.Facility_Recommendation_Code_For_Trainee == update_program.Facility_Recommendation_Code_For_Trainee); if (up_program == null) { return(false); } else if (up_program != null) { up_program.Personal_Weight_To_Lift = update_program.Personal_Weight_To_Lift; up_program.Amount_Of_Personal_Repetitions = update_program.Amount_Of_Personal_Repetitions; try { db.SaveChanges(); return(true); } catch { return(false); } } return(false); }
//מתודה למחיקת מתקן public static bool DeleteGymFacility(int facility_code) { ComputerGymDBContext db = new ComputerGymDBContext(); Gym_Facility gymFacility = db.Gym_Facility.SingleOrDefault(x => x.Facility_Code == facility_code); if (gymFacility == null) { return(false); } else if (gymFacility != null) { try { db.Gym_Facility.Remove(gymFacility); db.SaveChanges(); } catch (Exception) { return(false); } return(true); } return(false); }
//מתודה להוספת מאמן חדש public static bool AddTrainer(Trainer trainer) { ComputerGymDBContext db = new ComputerGymDBContext(); Trainer trainerToAdd = new Trainer(); trainerToAdd.Trainer_Id = trainer.Trainer_Id; trainerToAdd.First_Name = trainer.First_Name; trainerToAdd.Last_Name = trainer.Last_Name; trainerToAdd.User_Name = trainer.User_Name; trainerToAdd.Password = trainer.Password; trainerToAdd.Phone_Number = trainer.Phone_Number; try { db.Trainers.Add(trainerToAdd); db.SaveChanges(); } catch (Exception) { return(false); } try { } catch (Exception) { throw; } return(true); }
//מתודה לעדכון המלצה על מתקן של מתאמן מסויים public static bool UpdateTrainerFacilityRecommendations(Trainer_Facility_Recommendation trainer_facility_recommendation) { ComputerGymDBContext db = new ComputerGymDBContext(); Trainer_Facility_Recommendation trainerFacilityRecommendation = db.Trainer_Facility_Recommendation.SingleOrDefault(x => x.Facility_Recommendation_Code_For_Trainee == trainer_facility_recommendation.Facility_Recommendation_Code_For_Trainee); if (trainerFacilityRecommendation == null) { return(false); } else if (trainerFacilityRecommendation != null) { trainerFacilityRecommendation.Recommended_Weight_To_Lift = trainer_facility_recommendation.Recommended_Weight_To_Lift; trainerFacilityRecommendation.Amount_Of_Recommended_Repetitions = trainer_facility_recommendation.Amount_Of_Recommended_Repetitions; try { db.SaveChanges(); return(true); } catch (Exception) { return(false); } } return(false); }
//מתודה למחיקת קישור למתקן public static bool DeleteFacilityVideoLink(int video_link_code) { ComputerGymDBContext db = new ComputerGymDBContext(); Facility_Video_Link facilityVideoLink = db.Facility_Video_Link.SingleOrDefault(x => x.Video_Link_Code == video_link_code); if (facilityVideoLink == null) { return(false); } else if (facilityVideoLink != null) { try { db.Facility_Video_Link.Remove(facilityVideoLink); db.SaveChanges(); return(true); } catch (Exception) { return(false); } } return(false); }
// Get trainee training program public static TraineeTrainingProgramDTO GetTrianeeTrainingProgram(string Trainee_id) { ComputerGymDBContext db = new ComputerGymDBContext(); TraineeTrainingProgramDTO program = new TraineeTrainingProgramDTO(); program.trainingProgram = GetTrianeeTrainingProgramFacilities(Trainee_id); return(program); }
// DataBaseConnection. //מתודה להחזרת שם משתמש וסיסמא כדי לאמת התחברות של מאמן //אם לא קיים מחזיר null public static TrainerIdAndPasswordDTO GetTrainerIdAndPassword(string trainer_id) { ComputerGymDBContext db = new ComputerGymDBContext(); return(db.Trainers.Select(x => new TrainerIdAndPasswordDTO() { Password = x.Password, Trainer_Id = x.Trainer_Id, }).SingleOrDefault(x => x.Trainer_Id == trainer_id)); }
//מתודה להחזרת כל קישורי כל המתקנים public static List <FacilityVideoLinkDTO> GetFacilityVideoLink() { ComputerGymDBContext db = new ComputerGymDBContext(); return(db.Facility_Video_Link.Select(s => new FacilityVideoLinkDTO() { Video_Link_Code = s.Video_Link_Code, Facility_Code = s.Facility_Code, Video_Link = s.Video_Link }).OrderBy(s => s.Facility_Code).ToList()); }
//מתודה להחזרת כל מתקני המכון public static List <GymFacilityDTO> GetAllGymFacilities() { ComputerGymDBContext db = new ComputerGymDBContext(); return(db.Gym_Facility.Select(s => new GymFacilityDTO() { Big_Muscle = s.Big_Muscle, Facility_Code = s.Facility_Code, Category = s.Category, Facility_Name = s.Facility_Name, Picture = s.Picture, }).OrderBy(s => s.Category).ToList()); }
// Get all facility in the Gym public static List <GymFacilitiesDTO> GetAllGymFacilitiesForAlgoritem() { ComputerGymDBContext db = new ComputerGymDBContext(); List <GymFacilitiesDTO> all_facility_in_gym = db.Gym_Facility.Select(s => new GymFacilitiesDTO() { Facility_Code = s.Facility_Code, Facility_Name = s.Facility_Name, Category = s.Category, Big_Muscle = s.Big_Muscle }).OrderByDescending(x => x.Category).ToList(); return(all_facility_in_gym); }
//מתודה להחזרת פרטים של מאמן כדי להציגם בדף שלו //אם לא קיים מחזיר null public static TrainerDTO GetTrainer(string trainer_id) { ComputerGymDBContext db = new ComputerGymDBContext(); return(db.Trainers.Select(x => new TrainerDTO() { Trainer_Id = x.Trainer_Id, First_Name = x.First_Name, Last_Name = x.Last_Name, User_Name = x.User_Name, Password = x.Password, Phone_Number = x.Phone_Number, }).SingleOrDefault(x => x.Trainer_Id == trainer_id)); }
//מתודה להחזרת כל ההמלצות על מתקנים של מתאמן מסויים כדי שהמאמן יוכל לשנות אותם במידת הצורך public static List <TrainerFacilityRecommendationDTO> GetTrainerFacilityRecommendations(string trainer_id, string trainee_id) { ComputerGymDBContext db = new ComputerGymDBContext(); return(db.Trainer_Facility_Recommendation.Where(x => x.Trainee_Id == trainee_id && x.Trainer_Id == trainer_id) .Select(x => new TrainerFacilityRecommendationDTO() { Amount_Of_Recommended_Repetitions = x.Amount_Of_Recommended_Repetitions, Facility_Code = x.Facility_Code, Facility_Recommendation_Code_For_Trainee = x.Facility_Recommendation_Code_For_Trainee, Recommended_Weight_To_Lift = x.Recommended_Weight_To_Lift, Trainee_Id = x.Trainee_Id, Trainer_Id = x.Trainer_Id, }).OrderBy(x => x.Facility_Code).ToList()); }
//מתודה להחזרת כל מתקני המכון ולכל מתקן את רשימת הקישורים שלו public static List <AllGymFacilitiesAndVideoLinkDTO> GetAllGymFacilitiesAndVideoLink() { ComputerGymDBContext db = new ComputerGymDBContext(); return(db.Gym_Facility.Select(s => new AllGymFacilitiesAndVideoLinkDTO() { Facility_Code = s.Facility_Code, Category = s.Category, Facility_Name = s.Facility_Name, Picture = s.Picture, Video_Links = s.Facility_Video_Link.Select(a => new FacilityVideoLinkDTO() { Video_Link = a.Video_Link, Video_Link_Code = a.Video_Link_Code, Facility_Code = a.Facility_Code, }).ToList() }).OrderBy(z => z.Category).ToList()); }
// Get all facility for history trainee training program private static List <TraineeHistoryFacilitiesDTO> GetTrianeeHistoryFacilities(string Trainee_id) { ComputerGymDBContext db = new ComputerGymDBContext(); List <TraineeHistoryFacilitiesDTO> program = db.Trainee_Facilities_History .Where(x => x.Trainee_Id == Trainee_id) .OrderBy(q => q.Creation_Date) .Select(s => new TraineeHistoryFacilitiesDTO() { Facility_Name = s.Trainee.Trainer_Facility_Recommendation.FirstOrDefault(c => c.Facility_Code == s.Facility_Code).Gym_Facility.Facility_Name, Category = s.Trainee.Trainer_Facility_Recommendation.FirstOrDefault(c => c.Facility_Code == s.Facility_Code).Gym_Facility.Category, Amount_Of_Personal_Repetitions = s.Amount_Of_Personal_Repetitions, Personal_Weight_To_Lift = s.Personal_Weight_To_Lift, Facility_Code = s.Facility_Code, Creation_Date = s.Creation_Date }).ToList(); return(program); }
//מתודה להוספה של קישור למתקן public static int AddFacilityVideoLink(Facility_Video_Link facility_video_link) { ComputerGymDBContext db = new ComputerGymDBContext(); Facility_Video_Link facilityVideoLink = new Facility_Video_Link(); facilityVideoLink.Facility_Code = facility_video_link.Facility_Code; facilityVideoLink.Video_Link = facility_video_link.Video_Link; try { db.Facility_Video_Link.Add(facilityVideoLink); db.SaveChanges(); } catch (Exception) { return(-1); } return(facilityVideoLink.Video_Link_Code); }
//POST Trainee Program public static bool AddNewTraineeProgram(List <Trainer_Facility_Recommendation> add_program) { ComputerGymDBContext db = new ComputerGymDBContext(); for (int i = 0; i < add_program.Count; i++) { db.Trainer_Facility_Recommendation.Add(add_program[i]); } try { db.SaveChanges(); } catch { return(false); } return(true); }
// Get all facility for trainee training program private static List <TraineeTrainingProgramFacilityDTO> GetTrianeeTrainingProgramFacilities(string Trainee_id) { ComputerGymDBContext db = new ComputerGymDBContext(); List <TraineeTrainingProgramFacilityDTO> program = db.Trainer_Facility_Recommendation .Where(x => x.Trainee_Id == Trainee_id) .OrderByDescending(q => q.Creation_Date) .Select(s => new TraineeTrainingProgramFacilityDTO() { Facility_Code = s.Facility_Code, Amount_Of_Recommended_Repetitions = s.Amount_Of_Recommended_Repetitions, Amount_Of_Personal_Repetitions = s.Amount_Of_Personal_Repetitions, Recommended_Weight_To_Lift = s.Recommended_Weight_To_Lift, Personal_Weight_To_Lift = s.Personal_Weight_To_Lift, Days_to_Train = s.Days_to_Train, Facility_Name = s.Gym_Facility.Facility_Name, Category = s.Gym_Facility.Category, Facility_Recommendation_Code_For_Trainee = s.Facility_Recommendation_Code_For_Trainee }).ToList(); return(program); }
//Put Trainee Details public static bool UpdateTraineeDetails(Trainee traineeDetails) { ComputerGymDBContext db = new ComputerGymDBContext(); Trainee trainee = db.Trainees.SingleOrDefault(x => x.Trainee_Id == traineeDetails.Trainee_Id); if (trainee == null) { return(false); } else if (trainee != null) { trainee.First_Name = traineeDetails.First_Name; trainee.Last_Name = traineeDetails.Last_Name; trainee.User_Name = traineeDetails.User_Name; trainee.Password = traineeDetails.Password; trainee.Phone_Number = traineeDetails.Phone_Number; trainee.Date_Of_Birth = traineeDetails.Date_Of_Birth; trainee.Height = traineeDetails.Height; trainee.Weight = traineeDetails.Weight; trainee.Gender = traineeDetails.Gender; trainee.Address = traineeDetails.Address; trainee.Amount_Of_Training_Per_Week = traineeDetails.Amount_Of_Training_Per_Week; trainee.Perform_Exercises = traineeDetails.Perform_Exercises; trainee.Training_Goal = traineeDetails.Training_Goal; trainee.Fitness_Level = traineeDetails.Fitness_Level; trainee.Body_Problem = traineeDetails.Body_Problem; try { db.SaveChanges(); return(true); } catch { return(false); } } return(false); }
//POST Trainee History public static bool AddLineInHistory(Trainee_Facilities_History history) { ComputerGymDBContext db = new ComputerGymDBContext(); Trainee_Facilities_History add_history_trainee = new Trainee_Facilities_History(); add_history_trainee.Trainee_Id = history.Trainee_Id; add_history_trainee.Amount_Of_Personal_Repetitions = history.Amount_Of_Personal_Repetitions; add_history_trainee.Personal_Weight_To_Lift = history.Personal_Weight_To_Lift; add_history_trainee.Creation_Date = DateTime.Today; add_history_trainee.Facility_Code = history.Facility_Code; try { db.Trainee_Facilities_History.Add(add_history_trainee); db.SaveChanges(); } catch { return(false); } return(true); }
//מתודה להוספת מתקן public static int AddGymFacility(Gym_Facility gym_facility) { ComputerGymDBContext db = new ComputerGymDBContext(); Gym_Facility gymFacility = new Gym_Facility(); gymFacility.Category = gym_facility.Category; gymFacility.Facility_Name = gym_facility.Facility_Name; gymFacility.Picture = gym_facility.Picture; gymFacility.Big_Muscle = gym_facility.Big_Muscle; try { db.Gym_Facility.Add(gymFacility); db.SaveChanges(); } catch (Exception) { return(-1); } return(gymFacility.Facility_Code); }