Example #1
0
 public StatisticViewModel(StatisticManagementBussiness bussiness)
 {
     Finance       = new FinanceViewModel(bussiness.Finance);
     Teacher       = new TeacherViewModel(bussiness.Teacher);
     Trainee       = new TraineeViewModel(bussiness.Trainee);
     General       = new GeneralViewModel(bussiness.General);
     StatisticFunc = 3;
 }
        public ActionResult CreateTrainee()
        {
            TraineeViewModel model = new TraineeViewModel()
            {
                ProgrammingLanguages = _context.ProgrammingLanguages.ToList()
            };

            return(View(model));
        }
Example #3
0
        protected void AssignWorkout_OnClick(object sender, EventArgs e)
        {
            trainee = tbll.GetTraineeById(Convert.ToInt32(Request.QueryString["TraineeID"]));

            trainee.WorkoutID = Convert.ToInt32(WorkoutDropdownList.SelectedItem.Value);

            tbll.EditTrainee(trainee);

            Response.Redirect("~/Trainees.aspx");
        }
 protected void WorkoutAssignButton_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         TraineeViewModel trainee = tbll.GetTraineeById(Convert.ToInt32(Request.QueryString["TraineeID"]));
         trainee.TraineeID = Convert.ToInt32(Request.QueryString["TraineeID"]);
         trainee.WorkoutID = Convert.ToInt32(WorkoutList.SelectedValue);
         tbll.AssignWorkout(trainee);
         Response.Redirect("~/Trainees.aspx");
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                TraineeViewModel trainee = trainee_BLL.GetTraineeById(Convert.ToInt32(Request.QueryString["TraineeID"]));
                TraineeNameLabel.Text = trainee.FirstName + " " + trainee.LastName;

                ddlWorkouts.DataSource     = workout_BLL.GetAllWorkouts();
                ddlWorkouts.DataTextField  = "WorkoutName";
                ddlWorkouts.DataValueField = "WorkoutID";       // not sure if I need this line
                ddlWorkouts.DataBind();
            }
        }
Example #6
0
        private void BindData()
        {
            // Store and Display Trainee's Name
            TraineeViewModel trainee = traineeBLL.GetTraineeById(Convert.ToInt32(Request.QueryString["TraineeID"]));

            TraineeName.Text = (trainee.FirstName + " " + trainee.LastName).ToUpper();

            // Retrieve all workouts
            List <WorkoutViewModel> workouts = workoutBLL.GetAllWorkouts();

            WorkoutDropList.DataSource = workouts;
            WorkoutDropList.DataBind();
        }
Example #7
0
        public ActionResult Edit()
        {
            var role  = (from r in _context.Roles where r.Name.Contains("Trainee") select r).FirstOrDefault();
            var users = _context.Users.Where(x => x.Roles.Select(y => y.RoleId).Contains(role.Id)).ToList();

            var TraineeVM = new TraineeViewModel()
            {
                Trainees    = users,
                TraineeInfo = new TraineeInfo()
            };

            return(View(TraineeVM));
        }
        public int AssignWorkout(TraineeViewModel trainee)
        {
            string sqlQuery = "Update Trainee Set WorkoutID=@WorkoutID Where TraineeID=@ID";

            //No need to use SqlDataReader here since we are just using the Sql Query to persist to database
            using (SqlConnection con = new SqlConnection(_connectionString))
                using (SqlCommand cmd = new SqlCommand(sqlQuery, con))
                {
                    con.Open();
                    cmd.Parameters.Add("@ID", SqlDbType.Int).Value        = trainee.TraineeID;
                    cmd.Parameters.Add("@WorkoutID", SqlDbType.Int).Value = trainee.WorkoutID;
                    return(cmd.ExecuteNonQuery());
                }
        }
Example #9
0
        //Returns All Trainees
        public List <TraineeViewModel> GetTrainees()
        {
            //SQL command for selecting all from Trainee table
            string sqlQuery = "SELECT * FROM Trainee";

            //Empty list of TraineeViewModel to add and return
            List <TraineeViewModel> trainees = new List <TraineeViewModel>();

            //Using SqlConnection to establish connection to database
            //using SqlCommand passing in the SqlConnection and the sqlQuery
            using (SqlConnection con = new SqlConnection(_connectionString))
                using (SqlCommand cmd = new SqlCommand(sqlQuery, con))
                {
                    //open the connection
                    con.Open();
                    //SqlDataReader is used because we are reading data from the database
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        //while there are records in the database
                        while (reader.Read())
                        {
                            //store each value into the properties of TraineeViewModel
                            TraineeViewModel temp = new TraineeViewModel()
                            {
                                TraineeID = Convert.ToInt32(reader["TraineeID"]),
                                FirstName = reader["FirstName"].ToString(),
                                LastName  = reader["LastName"].ToString(),
                                Email     = reader["Email"].ToString(),
                                Height    = Convert.ToInt32(reader["Height"]),
                                Weight    = Convert.ToInt32(reader["Weight"]),
                                CellNbr   = reader["CellNbr"].ToString(),
                                Gender    = reader["Gender"].ToString(),
                                Age       = Convert.ToInt32(reader["Age"])
                            };

                            // Check if there is an associated WorkoutID with the Trainee
                            // and assign to Trainee if it exists
                            if (!DBNull.Value.Equals(reader["WorkoutID"]))
                            {
                                temp.WorkoutID        = Convert.ToInt32(reader["WorkoutID"]);
                                temp.bWorkoutAssigned = true;
                            }

                            //Add the Trainee object to the List of Trainee
                            trainees.Add(temp);
                        }
                    }
                }
            return(trainees);
        }
Example #10
0
        public int AssignWorkout(int traineeID, int workoutID)
        {
            TraineeViewModel trainee  = GetTraineeById(traineeID);
            string           sqlQuery = "Update Trainee Set WorkoutID=@WorkoutID Where TraineeID=@ID";

            using (SqlConnection con = new SqlConnection(_connectionString))
                using (SqlCommand cmd = new SqlCommand(sqlQuery, con))
                {
                    con.Open();
                    cmd.Parameters.Add("@ID", SqlDbType.Int).Value        = traineeID;
                    cmd.Parameters.Add("@WorkoutID", SqlDbType.Int).Value = workoutID;
                    trainee.bWorkoutAssigned = true;
                    return(cmd.ExecuteNonQuery());
                }
        }
        protected void AssignWorkoutButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                // this line prints an integer successfully
                WorkoutViewModel workout = workout_BLL.GetWorkoutById(Convert.ToInt32(ddlWorkouts.SelectedValue));
                TraineeViewModel trainee = trainee_BLL.GetTraineeById(Convert.ToInt32(Request.QueryString["TraineeID"]));
                trainee.WorkoutID = workout.WorkoutID;


                trainee_BLL.EditTrainee(trainee);

                Response.Redirect("~/Trainees.aspx");
            }
        }
        public ActionResult EditTrainee(TraineeViewModel model)
        {
            var findTrainee = _context.Users.OfType <Trainee>().SingleOrDefault(t => t.Id == model.Id);

            findTrainee.TraineeName           = model.TraineeName;
            findTrainee.Email                 = model.Email;
            findTrainee.Age                   = model.Age;
            findTrainee.DateOfBirth           = model.DateOfBirth;
            findTrainee.TOEICScore            = model.TOEICScore;
            findTrainee.ExperienceDetails     = model.ExperienceDetails;
            findTrainee.Department            = model.Department;
            findTrainee.Location              = model.Location;
            findTrainee.ProgrammingLanguageId = model.ProgrammingLanguageId;
            _context.SaveChanges();
            return(RedirectToAction("AllTrainee"));
        }
Example #13
0
        public TraineeViewModel ToTraineeViewModel(Trainee trainee, int reviewerId = 0)
        {
            var mentorProfileViewModel = new TraineeViewModel
            {
                Id              = trainee.Id,
                FullName        = trainee.User.FullName,
                Specialization  = trainee.Specialization.Name,
                Project         = trainee.Group.Project.Name,
                ReleaseDuration = GetReleaseDuration(trainee.Group),
                Command         = trainee.Group.Number,
                IsAllowed       = trainee.IsAllowed,
                IsReviewed      = trainee.ReviewsOnMe.Any(t => t.ReviewerId == reviewerId)
            };

            return(mentorProfileViewModel);
        }
Example #14
0
 public ActionResult Create(TraineeViewModel tvm, string returnurl = "")
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (tvm.Photo != null)
             {
                 string filename = Guid.NewGuid().ToString() + Path.GetExtension(tvm.Photo.FileName);
                 string filepath = Path.Combine("Images", "Trainee", filename);
                 string file     = Path.Combine(Server.MapPath("~/" + filepath));
                 tvm.Photo.SaveAs(file);
                 Trainee trainer = new Trainee
                 {
                     Name       = tvm.Name,
                     FatherName = tvm.FatherName,
                     Email      = tvm.Email,
                     Gender     = tvm.Gender,
                     BirthDate  = tvm.BirthDate,
                     NID        = tvm.NID,
                     Phone      = tvm.Phone,
                     Address    = tvm.Address,
                     UserName   = tvm.UserName,
                     PhotoPath  = filepath
                 };
                 db.Trainees.Add(trainer);
                 db.SaveChanges();
                 if (Url.IsLocalUrl(returnurl))
                 {
                     return(Redirect(returnurl));
                 }
                 else
                 {
                     return(RedirectToAction("Index", "Course"));
                 }
             }
         }
         throw new Exception();
     }
     catch
     {
         return(View());
     }
 }
Example #15
0
        //Returns All Trainees
        public List <TraineeViewModel> GetTrainees()
        {
            //SQL command for selecting all from Trainee table
            string sqlQuery = "SELECT * FROM Trainee";

            //Empty list of TraineeViewModel to add and return
            List <TraineeViewModel> trainees = new List <TraineeViewModel>();

            //Using SqlConnection to establish connection to database
            //using SqlCommand passing in the SqlConnection and the sqlQuery
            using (SqlConnection con = new SqlConnection(_connectionString))
                using (SqlCommand cmd = new SqlCommand(sqlQuery, con))
                {
                    //open the connection
                    con.Open();
                    //SqlDataReader is used because we are reading data from the database
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        //while there are records in the database
                        while (reader.Read())
                        {
                            //store each value into the properties of TraineeViewModel
                            string           k    = reader["WorkoutID"].ToString();
                            TraineeViewModel temp = new TraineeViewModel()
                            {
                                TraineeID = Convert.ToInt32(reader["TraineeID"]),
                                FirstName = reader["FirstName"].ToString(),
                                LastName  = reader["LastName"].ToString(),
                                Email     = reader["Email"].ToString(),
                                Height    = Convert.ToInt32(reader["Height"]),
                                Weight    = Convert.ToInt32(reader["Weight"]),
                                CellNbr   = reader["CellNbr"].ToString(),
                                Gender    = reader["Gender"].ToString(),
                                Age       = Convert.ToInt32(reader["Age"]),
                                WorkoutID = Convert.ToInt32(reader["WorkoutID"].ToString().CompareTo("") == 0 ? "0" : reader["WorkoutID"])
                                            //WorkoutID = Convert.ToInt32(reader.IsDBNull(9) ? "0" : reader["WorkoutID"])
                            };
                            //Add the Trainee object to the List of Trainee
                            trainees.Add(temp);
                        }
                    }
                }
            return(trainees);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //using GetTraineeById method to get the Trainee from the database, which we use to
                //populate the data into the form.
                TraineeViewModel trainee = tbll.GetTraineeById(Convert.ToInt32(Request.QueryString["TraineeID"]));
                FullName.Text = trainee.FirstName + " " + trainee.LastName;

                WorkoutBLL wbll = new WorkoutBLL(ConfigurationManager.ConnectionStrings["MySwoleMateConnectionString"].ToString());
                List <WorkoutViewModel> workouts = wbll.GetAllWorkouts();

                WorkoutList.DataSource     = workouts;
                WorkoutList.DataTextField  = "WorkoutName";
                WorkoutList.DataValueField = "WorkoutID";
                WorkoutList.DataBind();
                WorkoutList.Items.Insert(0, "--Select an option--");
            }
        }
Example #17
0
        public ActionResult Assign(TraineeViewModel traineeViewModel)
        {
            var role  = (from r in _context.Roles where r.Name.Contains("Trainee") select r).FirstOrDefault();
            var users = _context.Users.Where(x => x.Roles.Select(y => y.RoleId).Contains(role.Id)).ToList();

            if (ModelState.IsValid)
            {
                _context.TraineeInfos.Add(traineeViewModel.TraineeInfo);
                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }

            var TraineeVM = new TraineeViewModel()
            {
                Trainees    = users,
                TraineeInfo = new TraineeInfo(),
            };

            return(View(TraineeVM));
        }
        public async Task <ActionResult> CreateTrainee(TraineeViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new Trainee {
                    UserName = model.Email, Email = model.Email, DateOfBirth = model.DateOfBirth, ProgrammingLanguageId = model.ProgrammingLanguageId, TraineeName = model.TraineeName, Age = model.Age, Department = model.Department, Location = model.Location, ExperienceDetails = model.ExperienceDetails
                };

                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var userRole = UserManager.AddToRole(user.Id, "Trainee");
                    return(RedirectToAction("AllTrainee"));
                }
                AddErrors(result);
            }

            return(View(model));
        }
Example #19
0
        public ActionResult Create()
        {
            ViewBag.IsCreate = true;
            var academicMajorResult = _academicMajorService.Get();

            if (!academicMajorResult.Success)
            {
                var status = new StatusModel(false, academicMajorResult.Message);
                return(Error(status));
            }
            var academicInstitutionResult = _academicInstitutionService.Get(CurrentUser.Area);

            if (!academicInstitutionResult.Success)
            {
                var status = new StatusModel(false, academicMajorResult.Message);
                return(Error(status));
            }

            TraineeViewModel model = new TraineeViewModel
            {
                AcademicInstitutionList = academicInstitutionResult.Data,
                AcademicMajorList       = academicMajorResult.Data,
                Trainee = new TraineeModel()
                {
                    Birthday = DateTime.Now
                }
            };

            model.Trainee.User = new UserModel();
            if (CurrentUser.UserRole == UserRole.Admin)
            {
                ViewBag.IsRackaz = false;
            }
            else
            {
                model.Trainee.User.Area = CurrentUser.Area;
                ViewBag.IsRackaz        = true;
            }

            return(View(model));
        }
Example #20
0
        //Edits Trainee using "UPDATE" Sql Query passing in values to edit depending on the TraineeID
        public int EditTrainee(TraineeViewModel edit)
        {
            string sqlQuery;

            if (edit.WorkoutID != 0)        // ints can't be null, but all workoutIDs > 0 if they exist so this works
            {
                sqlQuery = "Update Trainee Set FirstName=@FirstName, LastName=@LastName, " +
                           "Email=@Email, Height=@Height, Weight=@Weight, CellNbr=@CellNbr, Gender=@Gender, " +
                           "Age=@Age, WorkoutID=@WorkoutID Where TraineeID=@ID";
            }
            else
            {
                sqlQuery = "Update Trainee Set FirstName=@FirstName, LastName=@LastName, " +
                           "Email=@Email, Height=@Height, Weight=@Weight, CellNbr=@CellNbr, Gender=@Gender, " +
                           "Age=@Age Where TraineeID=@ID";
            }


            //No need to use SqlDataReader here since we are just using the Sql Query to persist to database
            using (SqlConnection con = new SqlConnection(_connectionString))
                using (SqlCommand cmd = new SqlCommand(sqlQuery, con))
                {
                    con.Open();
                    cmd.Parameters.Add("@ID", SqlDbType.Int).Value            = edit.TraineeID;
                    cmd.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = edit.FirstName;
                    cmd.Parameters.Add("@LastName", SqlDbType.VarChar).Value  = edit.LastName;
                    cmd.Parameters.Add("@Email", SqlDbType.VarChar).Value     = edit.Email;
                    cmd.Parameters.Add("@Height", SqlDbType.Int).Value        = edit.Height;
                    cmd.Parameters.Add("@Weight", SqlDbType.Int).Value        = edit.Weight;
                    cmd.Parameters.Add("@CellNbr", SqlDbType.VarChar).Value   = edit.CellNbr;
                    cmd.Parameters.Add("@Gender", SqlDbType.VarChar).Value    = edit.Gender;
                    cmd.Parameters.Add("@Age", SqlDbType.Int).Value           = edit.Age;

                    if (edit.WorkoutID != null)
                    {
                        cmd.Parameters.Add("@WorkoutID", SqlDbType.Int).Value = edit.WorkoutID;
                    }

                    return(cmd.ExecuteNonQuery());
                }
        }
Example #21
0
 /// <summary>
 /// Method for Load event to load values into the form for edit
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void Page_Load(object sender, EventArgs e)
 {
     //Only load the values if the request is not a PostBack
     if (!IsPostBack)
     {
         //We pass the TraineeID by a Query String from the GridView on Trainees.aspx. See how we passed
         //TraineeID to this page from Trainees.aspx by looking at HyperLinkField in the GridView control
         //on the Trainees.aspx page for clarification
         TraineeViewModel trainee = bll.GetTraineeById(Convert.ToInt32(Request.QueryString["TraineeID"]));
         //We use the GetTraineeById method to get the Trainee from the database, which we use to
         //populate the data into the form.
         FirstName.Text       = trainee.FirstName;
         LastName.Text        = trainee.LastName;
         Email.Text           = trainee.Email;
         Height.Text          = trainee.Height.ToString();
         Weight.Text          = trainee.Weight.ToString();
         CellNbr.Text         = trainee.CellNbr;
         Gender.SelectedValue = trainee.Gender;
         Age.Text             = trainee.Age.ToString();
     }
 }
Example #22
0
        //Add Trainee using "INSERT" Sql Query depending on the values, very similar to EditTrainee
        //method above
        public int AddTrainee(TraineeViewModel add)
        {
            string sqlQuery = "INSERT into Trainee (FirstName, LastName, Email, Height, " +
                              "Weight, CellNbr, Gender, Age) VALUES (@FirstName, @LastName, @Email, @Height, " +
                              "@Weight, @CellNbr, @Gender, @Age)";

            using (SqlConnection con = new SqlConnection(_connectionString))
                using (SqlCommand cmd = new SqlCommand(sqlQuery, con))
                {
                    con.Open();
                    cmd.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = add.FirstName;
                    cmd.Parameters.Add("@LastName", SqlDbType.VarChar).Value  = add.LastName;
                    cmd.Parameters.Add("@Email", SqlDbType.VarChar).Value     = add.Email;
                    cmd.Parameters.Add("@Height", SqlDbType.Int).Value        = add.Height;
                    cmd.Parameters.Add("@Weight", SqlDbType.Int).Value        = add.Weight;
                    cmd.Parameters.Add("@CellNbr", SqlDbType.VarChar).Value   = add.CellNbr;
                    cmd.Parameters.Add("@Gender", SqlDbType.VarChar).Value    = add.Gender;
                    cmd.Parameters.Add("@Age", SqlDbType.Int).Value           = add.Age;
                    return(cmd.ExecuteNonQuery());
                }
        }
 protected void TraineeEditButton_Click(object sender, EventArgs e)
 {
     //Check to see if all ValidationControls are valid
     if (Page.IsValid)
     {
         //Create new empty ViewModel to pass in the new values
         TraineeViewModel trainee = new TraineeViewModel();
         //Use the same query string to fill the ID
         trainee.TraineeID = Convert.ToInt32(Request.QueryString["TraineeID"]);
         trainee.FirstName = FirstName.Text;
         trainee.LastName  = LastName.Text;
         trainee.Email     = Email.Text;
         trainee.Height    = Convert.ToInt32(Height.Text);
         trainee.Weight    = Convert.ToInt32(Weight.Text);
         trainee.CellNbr   = CellNbr.Text;
         trainee.Gender    = Gender.SelectedValue;
         trainee.Age       = Convert.ToInt32(Age.Text);
         //Call the EditTrainee() method passing in the new values
         bll.EditTrainee(trainee);
         //Redirect to the Trainees.aspx page
         Response.Redirect("~/Trainees.aspx");
     }
 }
Example #24
0
        //Get Trainee By Id, returns one instance of TraineeViewModel
        //Very similar to GetTrainees() method above
        public TraineeViewModel GetTraineeById(int id)
        {
            TraineeViewModel trainee  = new TraineeViewModel();
            string           sqlQuery = "Select * from Trainee where TraineeId=@ID";

            using (SqlConnection con = new SqlConnection(_connectionString))
                using (SqlCommand cmd = new SqlCommand(sqlQuery, con))
                {
                    con.Open();
                    cmd.Parameters.Add("@ID", SqlDbType.Int).Value = id;
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            trainee.TraineeID = Convert.ToInt32(reader["TraineeID"]);
                            trainee.FirstName = reader["FirstName"].ToString();
                            trainee.LastName  = reader["LastName"].ToString();
                            trainee.Email     = reader["Email"].ToString();
                            trainee.Height    = Convert.ToInt32(reader["Height"]);
                            trainee.Weight    = Convert.ToInt32(reader["Weight"]);
                            trainee.CellNbr   = reader["CellNbr"].ToString();
                            trainee.Gender    = reader["Gender"].ToString();
                            trainee.Age       = Convert.ToInt32(reader["Age"]);
                            if (Convert.IsDBNull(reader["WorkoutID"]))
                            {
                                trainee.WorkoutID = 0;
                            }
                            else
                            {
                                trainee.WorkoutID = Convert.ToInt32(reader["WorkoutID"]);
                            }
                        }
                    }
                }
            return(trainee);
        }
        public ActionResult EditTrainee(string Id)
        {
            var findTrainee = _context.Users.OfType <Trainee>().Include(t => t.ProgrammingLanguage).SingleOrDefault(t => t.Id == Id);

            if (findTrainee == null)
            {
                return(HttpNotFound());
            }
            TraineeViewModel model = new TraineeViewModel()
            {
                Id                   = findTrainee.Id,
                TraineeName          = findTrainee.TraineeName,
                Email                = findTrainee.Email,
                Age                  = findTrainee.Age,
                DateOfBirth          = findTrainee.DateOfBirth,
                TOEICScore           = findTrainee.TOEICScore,
                ExperienceDetails    = findTrainee.ExperienceDetails,
                Department           = findTrainee.Department,
                Location             = findTrainee.Location,
                ProgrammingLanguages = _context.ProgrammingLanguages.ToList()
            };

            return(View(model));
        }
Example #26
0
 public int AssignWorkout(TraineeViewModel trainee)
 {
     return(data.AssignWorkout(trainee));
 }
Example #27
0
 //Adds a new Trainee
 public int AddTrainee(TraineeViewModel add)
 {
     return(data.AddTrainee(add));
 }
Example #28
0
 //Edits the Trainee accepting a TraineeViewModel
 public int EditTrainee(TraineeViewModel edit)
 {
     return(data.EditTrainee(edit));
 }