public WorkoutLogDTO GetWorkoutLogs() { WorkoutLogDTO dto = new WorkoutLogDTO(); dto.workoutLogs = dao.GetWorkoutLogs(); return(dto); }
public WorkoutLogDTO GetWorkoutLogs(string keyword) { WorkoutLogDTO dto = new WorkoutLogDTO(); dto.workoutLogs = dao.GetWorkoutLogs(keyword); return(dto); }
//is workout null public bool CreateWorkoutLog(WorkoutLogDTO workout) { using (var dbTransaction = db.Database.BeginTransaction()) { try { int getUserID = (from cred in db.Credentials where workout.userName == cred.UserName select cred.UserID).FirstOrDefault(); WorkoutLog work = new WorkoutLog { UserID = getUserID, WorkoutType = workout.WorkoutType, Date_Time = workout.Date_Time, }; db.Workouts.Add(work); if (workout.WorkoutType.Equals("Cardio")) { Cardio card = new Cardio { CardioType = workout.CardioType, Distance = workout.Distance, Time = workout.Time }; db.Cardios.Add(card); } else if (workout.WorkoutType.Equals("WeightLifting")) { WeightLifting weight = new WeightLifting { LiftingType = workout.LiftingType, Reps = workout.Reps, Sets = workout.Sets }; db.WeightLiftings.Add(weight); } //add into database t he new instance and saves db.SaveChanges(); dbTransaction.Commit(); return(true); } catch (SqlException) { dbTransaction.Rollback(); return(false); } catch (DataException) { dbTransaction.Rollback(); return(false); } } }
public IHttpActionResult CreateWorkout(WorkoutLogDTO workout) { //ModelState.IsValid then the try catch WorkoutLoggerService service = new WorkoutLoggerService(); //change success bool response = service.Create(workout); if (response) { return(Ok("Workout has been added")); } else { return(Content(HttpStatusCode.BadRequest, "Workout addition has failed. Invalid Inputs.")); } }
public void ShowWorkoutLog() { bll = new WorkoutLogBLL(); if (issearch) { dto = bll.GetWorkoutLogs(keyword); } else { dto = bll.GetWorkoutLogs(); } this.dataGridView1.DataSource = dto.workoutLogs; this.dataGridView1.Columns["ID"].HeaderText = "編號"; this.dataGridView1.Columns["MemberID"].HeaderText = "會員編號"; this.dataGridView1.Columns["WorkoutName"].HeaderText = "運動項目"; this.dataGridView1.Columns["WorkoutHours"].HeaderText = "運動時間"; this.dataGridView1.Columns["Calories"].HeaderText = "消耗熱量"; this.dataGridView1.Columns["EditTime"].HeaderText = "編輯時間"; dataGridView1.Columns["WorkoutID"].Visible = false; //dataGridView1.Columns["EditTime"].Visible = false; issearch = false; }
public bool Create(WorkoutLogDTO w) { //IF NOT EQUAL CARDIO AND WEIGHTLIFTING return false if (!(w.WorkoutType.Equals("Cardio")) && !(w.WorkoutType.Equals("WeightLifting"))) { return(false); } //check if inputs are ints, if string it will return false //Cardio types have an initialized 0 for reps/sets if (!(w.Reps % 1 == 0)) { return(false); } if (!(w.Sets % 1 == 0)) { return(false); } var gateway = new WorkoutLogGateway(); //no transitive property //data structure must be considered when transferring to gateway return(gateway.CreateWorkoutLog(w)); }
private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e) { int ID = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["ID"].Value); dto = wlBll.GetWorkoutLogByID(ID); }