internal ProgramDTO getById(string programId) { ProgramDTO program; string queryString = "SELECT client_id FROM program " + " WHERE @id = id"; using (SqlConnection connection = EstablishingConnection.GetConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand(queryString, connection)) { command.Parameters.AddWithValue("@id", programId); SqlDataReader reader = command.ExecuteReader(); program = new ProgramDTO(); while (reader.Read()) { ProgramDTO programNew = new ProgramDTO { ClientId = (string)reader["client_id"], }; program = programNew; } connection.Close(); } return(program); } }
public int Edit(int id, int trainingTypeId, DateTime startTime, DateTime endTime, string description) { int numberOfAffectedRows; string queryString = "UPDATE training " + "SET training.description=@description_training, training.training_type_id=@training_type_id, " + " training.start_time=@start_time, training.end_time=@end_time " + "WHERE training.id = @training_id;"; using (SqlConnection connection = EstablishingConnection.GetConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand(queryString, connection)) { command.Parameters.AddWithValue("@training_type_id", trainingTypeId); command.Parameters.AddWithValue("@start_time", startTime); command.Parameters.AddWithValue("@end_time", endTime); command.Parameters.AddWithValue("@training_id", id); command.Parameters.AddWithValue("@description_training", description); numberOfAffectedRows = command.ExecuteNonQuery(); connection.Close(); } return(numberOfAffectedRows); } }
public int Create(string clientId, int goalTypeId, DateTime startTime, DateTime endTime, string description, bool isMeal) { int result = 0; using (SqlConnection connection = EstablishingConnection.GetConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand("CreateProgram", connection) { CommandType = System.Data.CommandType.StoredProcedure }) { command.Parameters.AddWithValue("@clientId", clientId); command.Parameters.AddWithValue("@goalTypeId", goalTypeId); command.Parameters.AddWithValue("@startTime", startTime); command.Parameters.AddWithValue("@endTime", endTime); command.Parameters.AddWithValue("@description", description); command.Parameters.AddWithValue("@isMeal", isMeal); command.Parameters.Add(new SqlParameter("@lastId", System.Data.SqlDbType.Int)).Direction = System.Data.ParameterDirection.Output; command.ExecuteNonQuery(); // result = Convert.ToInt32(command.ExecuteScalar()); //vrati nulu,ali doro upise u bazu -->rijeseno sa select scope result = (int)command.Parameters["@lastId"].Value; } } return(result); }
public List <ProgramDTO> GetAllPrograms(string clientId) { List <ProgramDTO> programs; string queryString = "SELECT * from program" + " WHERE program.client_id = @client_id"; using (SqlConnection connection = EstablishingConnection.GetConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand(queryString, connection)) { command.Parameters.AddWithValue("@client_id", clientId); SqlDataReader reader = command.ExecuteReader(); programs = new List <ProgramDTO>(); while (reader.Read()) { ProgramDTO program = new ProgramDTO { Id = (int)reader["id"], ClientId = (string)reader["client_id"], GoalTypeId = (int)reader["goal_type_id"], StartTime = Convert.ToDateTime(reader["start_time"]), EndTime = Convert.ToDateTime(reader["end_time"]), Description = (string)reader["description"] }; programs.Add(program); } connection.Close(); } return(programs); } }
public int Edit(string id, string firstName, string lastName, DateTime birthDate, DateTime registrationDate, string description) { int numberOfAffectedRows; string query = "UPDATE client " + "SET first_name=@firstName, last_name=@lastName, date_of_birth=@birthDate, registration_date=@registrationDate, description=@description " + "WHERE id = @id;"; using (SqlConnection connection = EstablishingConnection.GetConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand(query, connection)) { command.Parameters.AddWithValue("@id", id); command.Parameters.AddWithValue("@firstName", firstName); command.Parameters.AddWithValue("@lastName", lastName); command.Parameters.AddWithValue("@birthDate", birthDate); command.Parameters.AddWithValue("@registrationDate", registrationDate); command.Parameters.AddWithValue("@description", description); numberOfAffectedRows = command.ExecuteNonQuery(); connection.Close(); } return(numberOfAffectedRows); } }
public MealDTO GetById(int id) { MealDTO meal; string queryString = "SELECT * from meal" + " WHERE @meal_id = meal.id"; using (SqlConnection connection = EstablishingConnection.GetConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand(queryString, connection)) { command.Parameters.AddWithValue("@meal_id", id); SqlDataReader reader = command.ExecuteReader(); meal = new MealDTO(); while (reader.Read()) { MealDTO mealNew = new MealDTO { Id = (int)reader["id"], ProgramId = (int)reader["program_id"], MealTypeId = (int)reader["meal_type_id"], StartTime = Convert.ToDateTime(reader["start_time"]), Description = (string)reader["description"], }; meal = mealNew; } connection.Close(); } return(meal); } }
public string getClientFullNameByProgramId(int programId) { ClientDTO c; string queryString = "SELECT c.first_name, c.last_name FROM client c JOIN program p ON p.client_id=c.id " + "WHERE p.id=@programId"; using (SqlConnection connection = EstablishingConnection.GetConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand(queryString, connection)) { command.Parameters.AddWithValue("@programId", programId); SqlDataReader reader = command.ExecuteReader(); c = new ClientDTO(); while (reader.Read()) { ClientDTO clientNew = new ClientDTO { FirstName = (string)reader["first_name"], LastName = (string)reader["last_name"] }; c = clientNew; } connection.Close(); } return(c.FullName); } }
public TrainingDTO GetById(int id) { TrainingDTO training; string queryString = "SELECT * from training" + " WHERE @training_id = training.id"; using (SqlConnection connection = EstablishingConnection.GetConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand(queryString, connection)) { command.Parameters.AddWithValue("@training_id", id); SqlDataReader reader = command.ExecuteReader(); training = new TrainingDTO(); while (reader.Read()) { TrainingDTO trainingNew = new TrainingDTO { Id = (int)reader["id"], ProgramId = (int)reader["program_id"], TrainingTypeId = (int)reader["training_type_id"], StartTime = Convert.ToDateTime(reader["start_time"]), EndTime = Convert.ToDateTime(reader["end_time"]), Description = (string)reader["description"], }; training = trainingNew; } connection.Close(); } return(training); } }
public TrainingDTO getById(int Id) { TrainingDTO training; string query = "SELECT * FROM training WHERE id=@id "; using (SqlConnection connection = EstablishingConnection.GetConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand(query, connection)) { command.Parameters.AddWithValue("@id", Id); SqlDataReader reader = command.ExecuteReader(); training = new TrainingDTO(); while (reader.Read()) { TrainingDTO newTraining = new TrainingDTO() { Id = (int)reader["id"], Description = (string)reader["description"], StartTime = Convert.ToDateTime(reader["start_time"]), EndTime = Convert.ToDateTime(reader["end_time"]), ProgramId = (int)reader["program_id"], TrainingTypeId = (int)reader["training_type_id"] }; training = newTraining; } } connection.Close(); } return(training); }
public List <MealTypeDTO> GetAll() { List <MealTypeDTO> mealTypes; using (SqlConnection connection = EstablishingConnection.GetConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand("select * from meal_type", connection)) { SqlDataReader reader = command.ExecuteReader(); mealTypes = new List <MealTypeDTO>(); while (reader.Read()) { MealTypeDTO client = new MealTypeDTO { Id = (int)reader["id"], Name = (string)reader["name"], }; mealTypes.Add(client); } } return(mealTypes); } }
public MealTypeDTO getById(int Id) { MealTypeDTO mealTypeDTO; string query = "SELECT * FROM meal_type gt WHERE gt.id=@id "; using (SqlConnection connection = EstablishingConnection.GetConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand(query, connection)) { command.Parameters.AddWithValue("@id", Id); SqlDataReader reader = command.ExecuteReader(); mealTypeDTO = new MealTypeDTO(); while (reader.Read()) { MealTypeDTO newMealTypeDTO = new MealTypeDTO() { Id = (int)reader["id"], Name = (string)reader["name"] }; mealTypeDTO = newMealTypeDTO; } } connection.Close(); } return(mealTypeDTO); }
//OK public List <ClientDTO> GetAll() { List <ClientDTO> clients; using (SqlConnection connection = EstablishingConnection.GetConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand("select * from client", connection)) { SqlDataReader reader = command.ExecuteReader(); clients = new List <ClientDTO>(); while (reader.Read()) { ClientDTO client = new ClientDTO { Id = (string)reader["id"], FirstName = (string)reader["first_name"], LastName = (string)reader["last_name"], DateOfBirth = Convert.ToDateTime(reader["date_of_birth"]), RegistrationDate = Convert.ToDateTime(reader["registration_date"]), Description = (string)reader["description"] }; clients.Add(client); } } return(clients); } }
public List <TrainingTypeDTO> GetAll() { List <TrainingTypeDTO> trainingTypes; using (SqlConnection connection = EstablishingConnection.GetConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand("select * from training_type", connection)) { SqlDataReader reader = command.ExecuteReader(); trainingTypes = new List <TrainingTypeDTO>(); while (reader.Read()) { TrainingTypeDTO trainingType = new TrainingTypeDTO { Id = (int)reader["id"], Name = (string)reader["name"], }; trainingTypes.Add(trainingType); } } return(trainingTypes); } }
//OK public async Task <ActionResult> Create(string firstName, string lastName, DateTime dateOfBirth, DateTime registrationDate, string roleId, string email, string username, string password, bool emailConfirmed, bool phoneNumberConfirmed, bool twoFactorEnabled, bool lockoutEnabled, int accessFailedCount, string description = " ") { string id; var db = new ApplicationDbContext(); var userStore = new UserStore <ApplicationUser>(db); var userManager = new ApplicationUserManager(userStore); var user = new ApplicationUser { UserName = username, Email = email, EmailConfirmed = emailConfirmed, PhoneNumberConfirmed = phoneNumberConfirmed, TwoFactorEnabled = twoFactorEnabled, LockoutEnabled = lockoutEnabled, AccessFailedCount = accessFailedCount }; if (user != null) { var result = await userManager.CreateAsync(user, password); id = user.Id; if (result.Succeeded) { result = userManager.AddToRole(user.Id, Utility.CLIENT_ROLE); SendEmailWithCredentials(email, password); //todo: posalji e-mail ulogovanom korisniku //Dodavanje u moju bazu korisnika sa ZADANIM id-jem: /*using (SqlConnection connection = EstablishingConnection.GetConnection()) * { * connection.Open(); * using (SqlCommand command = new SqlCommand("SET IDENTITY_INSERT client ON " + * "insert into client (id, first_name, last_name, date_of_birth, registration_date, description)values( @id, @first_name, @last_name, @date_of_birth, @registration_date, @description " + * "SET IDENTITY_INSERT client OFF)", connection))*/ using (SqlConnection connection = EstablishingConnection.GetConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand("insert into client ( id, first_name, last_name, date_of_birth, registration_date, [description])values( @id, @first_name, @last_name, @date_of_birth, @registration_date, @description)", connection)) { command.Parameters.AddWithValue("@id", id); command.Parameters.AddWithValue("@first_name", firstName); command.Parameters.AddWithValue("@last_name", lastName); command.Parameters.AddWithValue("@date_of_birth", dateOfBirth); command.Parameters.AddWithValue("@registration_date", registrationDate); command.Parameters.AddWithValue("@description", description); // command.Parameters.Add(new SqlParameter("@id", System.Data.SqlDbType.NVarChar)).Direction = System.Data.ParameterDirection.Output; command.ExecuteNonQuery(); } connection.Close(); } return(RedirectToAction("Index", "Client")); } else { AddErrors(result); } } return(View("Error")); }
public List <ClientTrainingDTO> getTrainerTrainingsInPickedWeek(DateTime Monday) { List <ClientTrainingDTO> trainings; var training_type = 2;// todo Utility.TrainerTrainingType; string queryString = "SELECT t.id as id, t.program_id as program_id, t.training_type_id as training_type_id, t.start_time, t.end_time, t.description as description, c.id as client_id, c.first_name as first_name, c.last_name as last_name FROM training t " + "JOIN program p ON p.id=program_id " + "JOIN client c ON c.id=p.client_id " + " WHERE @training_type = training_type_id AND" + " t.start_time between @monday and @sunday"; using (SqlConnection connection = EstablishingConnection.GetConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand(queryString, connection)) { command.Parameters.AddWithValue("@training_type", training_type); var monday = Monday.Date; var sunday = Monday.AddDays(6); command.Parameters.AddWithValue("@monday", monday); command.Parameters.AddWithValue("@sunday", sunday); SqlDataReader reader = command.ExecuteReader(); trainings = new List <ClientTrainingDTO>(); while (reader.Read()) { ClientTrainingDTO training = new ClientTrainingDTO { Id = (int)reader["id"], //training id ProgramId = (int)reader["program_id"], TrainingTypeId = (int)reader["training_type_id"], StartTime = Convert.ToDateTime(reader["start_time"]), EndTime = Convert.ToDateTime(reader["end_time"]), Description = (string)reader["description"], ClientId = (string)reader["client_id"], FirstName = (string)reader["first_name"], LastName = (string)reader["last_name"] }; trainings.Add(training); } connection.Close(); } return(trainings); } }
//vraca treninge koji imaju taj opis i tip (taj su dan) public List <TrainingDTO> getTrainingsByDescriptionTypeDay(int programId, string description, DateTime startTime, int trainingTypeId) { List <TrainingDTO> trainingsInProgram; string queryString = "SELECT * from training" + " WHERE @description = training.description AND " + "@trainingTypeId = training.training_type_id AND" + " training.start_time between @startTimeMorning and @startTimeEvening AND " + " training.program_id = @programId"; // " start_time between @monday and @sunday"; using (SqlConnection connection = EstablishingConnection.GetConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand(queryString, connection)) { command.Parameters.AddWithValue("@description", description); command.Parameters.AddWithValue("@trainingTypeId", trainingTypeId); command.Parameters.AddWithValue("@programId", programId); var startTimeMorning = Utility.ChangeTime(startTime, 07, 0, 0); var startTimeEvening = Utility.ChangeTime(startTime, 22, 0, 0); command.Parameters.AddWithValue("@startTimeMorning", startTimeMorning); command.Parameters.AddWithValue("@startTimeEvening", startTimeEvening); SqlDataReader reader = command.ExecuteReader(); trainingsInProgram = new List <TrainingDTO>(); while (reader.Read()) { TrainingDTO program = new TrainingDTO { Id = (int)reader["id"], ProgramId = (int)reader["program_id"], TrainingTypeId = (int)reader["training_type_id"], StartTime = Convert.ToDateTime(reader["start_time"]), EndTime = Convert.ToDateTime(reader["end_time"]), Description = (string)reader["description"], }; trainingsInProgram.Add(program); } connection.Close(); } return(trainingsInProgram); } }
public List <TrainingDTO> getByProgram(int programId, DateTime startTime, DateTime endTime) { List <TrainingDTO> trainingsInProgram; string queryString = "SELECT * from training" + " WHERE @program_id = training.program_id AND" + " start_time between @monday and @sunday"; using (SqlConnection connection = EstablishingConnection.GetConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand(queryString, connection)) { command.Parameters.AddWithValue("@program_id", programId); //var monday = Utility.GetPickedMonday().Date;// GetThisWeekMonday().Date; // var sunday = Utility.ChangeTime(Utility.GetPickedSunday(), 22, 0, 0); var monday = startTime.Date;// GetThisWeekMonday().Date; var sunday = Utility.ChangeTime(endTime, 22, 0, 0); command.Parameters.AddWithValue("@monday", monday); command.Parameters.AddWithValue("@sunday", sunday); SqlDataReader reader = command.ExecuteReader(); trainingsInProgram = new List <TrainingDTO>(); while (reader.Read()) { TrainingDTO program = new TrainingDTO { Id = (int)reader["id"], ProgramId = (int)reader["program_id"], TrainingTypeId = (int)reader["training_type_id"], StartTime = Convert.ToDateTime(reader["start_time"]), EndTime = Convert.ToDateTime(reader["end_time"]), Description = (string)reader["description"], }; trainingsInProgram.Add(program); } connection.Close(); } return(trainingsInProgram); } }
public int Create(int programId, int trainingTypeId, DateTime startTime, object endTime, string description) { int id = 0; using (SqlConnection connection = EstablishingConnection.GetConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand("insert into training ( program_id, training_type_id, start_time, end_time, description)values( @program_id, @training_type_id, @start_time, @end_time, @description)", connection)) { command.Parameters.AddWithValue("@program_id", programId); command.Parameters.AddWithValue("@training_type_id", trainingTypeId); command.Parameters.AddWithValue("@start_time", startTime); command.Parameters.AddWithValue("@end_time", endTime); command.Parameters.AddWithValue("@description", description); command.Parameters.Add(new SqlParameter("@id", System.Data.SqlDbType.Int)).Direction = System.Data.ParameterDirection.Output; id = Convert.ToInt32(command.ExecuteScalar()); } } return(id); }
public int Edit(int id, string name) { int numberOfAffectedRows; string query = "UPDATE meal_type " + "SET name=@name WHERE id = @id;"; using (SqlConnection connection = EstablishingConnection.GetConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand(query, connection)) { command.Parameters.AddWithValue("@id", id); command.Parameters.AddWithValue("@name", name); numberOfAffectedRows = command.ExecuteNonQuery(); connection.Close(); } return(numberOfAffectedRows); } }
public int Create(string name) { int id = 0; string query = "IF NOT EXISTS (SELECT * FROM training_type d WHERE name = @name)" + "INSERT INTO training_type (name) values (@name)"; using (SqlConnection connection = EstablishingConnection.GetConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand(query, connection)) { command.Parameters.AddWithValue("@name", name); command.Parameters.Add(new SqlParameter("@id", System.Data.SqlDbType.Int)).Direction = System.Data.ParameterDirection.Output; command.ExecuteNonQuery(); id = Convert.ToInt32(command.ExecuteScalar()); } connection.Close(); } return(id); }
public void Delete(int id) { string query = "DELETE FROM meal_type WHERE id=@id"; using (SqlConnection connection = EstablishingConnection.GetConnection()) { try { connection.Open(); SqlCommand Command = new SqlCommand(query, connection); Command.Parameters.AddWithValue("@id", id); Command.ExecuteNonQuery(); } catch (Exception e) { } finally { connection.Close(); } } }
public void Edit(int id, int trainingTypeId, string description) { int numberOfAffectedRows; string queryString = "UPDATE training " + "SET training.description=@description_training, training.training_type_id=@training_type_id " + "WHERE training.id = @training_id;"; using (SqlConnection connection = EstablishingConnection.GetConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand(queryString, connection)) { command.Parameters.AddWithValue("@training_type_id", trainingTypeId); command.Parameters.AddWithValue("@training_id", id); command.Parameters.AddWithValue("@description_training", description); numberOfAffectedRows = command.ExecuteNonQuery(); connection.Close(); } } }
public int Edit(int id, string description) { int numberOfAffectedRows; string queryString = "UPDATE meal " + "SET meal.description=@description_meal " + "WHERE meal.id = @meal_id;"; using (SqlConnection connection = EstablishingConnection.GetConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand(queryString, connection)) { command.Parameters.AddWithValue("@meal_id", id); command.Parameters.AddWithValue("@description_meal", description); numberOfAffectedRows = command.ExecuteNonQuery(); connection.Close(); } return(numberOfAffectedRows); } }
//**** public ProgramGoalTypeDTO GetById(int Id) { ProgramGoalTypeDTO program; string queryString = "SELECT p.id as id_program, p.client_id as client_id, p.start_time as start_time, p.end_time as end_time, p.goal_type_id as goal_type_id, g.id, p.is_meal as is_meal, g.name as name, p.description as description FROM program p JOIN goal_type g ON goal_type_id = g.id" + " WHERE @id = p.id"; using (SqlConnection connection = EstablishingConnection.GetConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand(queryString, connection)) { command.Parameters.AddWithValue("@id", Id); SqlDataReader reader = command.ExecuteReader(); program = new ProgramGoalTypeDTO(); while (reader.Read()) { ProgramGoalTypeDTO programNew = new ProgramGoalTypeDTO { Id = (int)reader["id_program"], ClientId = (string)reader["client_id"], GoalTypeId = (int)reader["goal_type_id"], StartTime = Convert.ToDateTime(reader["start_time"]), EndTime = Convert.ToDateTime(reader["end_time"]), Description = (string)reader["description"], IsMeal = (bool)reader["is_meal"], Name = (string)reader["name"] }; program.ProgramType = Utility.setProgramType(program.IsMeal); program = programNew; } connection.Close(); } return(program); } }
internal int Create(int programId, int mealTypeId, DateTime date, string description) { int id = 0; using (SqlConnection connection = EstablishingConnection.GetConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand("insert into meal ( program_id, meal_type_id, start_time, description)values( @program_id, @meal_type_id, @start_time, @description)", connection)) { command.Parameters.AddWithValue("@program_id", programId); command.Parameters.AddWithValue("@meal_type_id", mealTypeId); command.Parameters.AddWithValue("@start_time", date); command.Parameters.AddWithValue("@description", description); command.Parameters.Add(new SqlParameter("@id", System.Data.SqlDbType.Int)).Direction = System.Data.ParameterDirection.Output; // command.ExecuteNonQuery(); // id = (int)command.Parameters["@id"].Value; // id = Convert.ToInt32(command.Parameters["@id"].Value); id = Convert.ToInt32(command.ExecuteScalar()); //Ovo mi ne vrati NULL od insertovanog reda, jer ovo izvrs ikomandu i onda vrati prvi red iy prve insertovane kolone } } return(id); }
//OK public string Create(string firstName, string lastName, DateTime dateOfBirth, DateTime registrationDate, string description) { // int id = 0; string id; using (SqlConnection connection = EstablishingConnection.GetConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand("insert into client ( first_name, last_name, date_of_birth, registration_date, description)values( @first_name, @last_name, @date_of_birth, @registration_date, @description)", connection)) { command.Parameters.AddWithValue("@first_name", firstName); command.Parameters.AddWithValue("@last_name", lastName); command.Parameters.AddWithValue("@date_of_birth", dateOfBirth); command.Parameters.AddWithValue("@registration_date", registrationDate); command.Parameters.AddWithValue("@description", description); // command.Parameters.Add(new SqlParameter("@id", System.Data.SqlDbType.Int)).Direction = System.Data.ParameterDirection.Output; command.Parameters.Add(new SqlParameter("@id", System.Data.SqlDbType.NVarChar)).Direction = System.Data.ParameterDirection.Output; command.ExecuteNonQuery(); id = (string)command.Parameters["@id"].Value; } } return(id); }