Example #1
0
        public ActionResult DeleteConfirmed(long id)
        {
            FTE fTE = db.FTEs.Find(id);

            db.FTEs.Remove(fTE);
            db.SaveChanges();
            return(Json("Delete successful"));
        }
Example #2
0
 public ActionResult Edit([Bind(Include = "ID,NRIC,UserID,FullName,Email,Contact")] FTE fTE)
 {
     if (ModelState.IsValid)
     {
         db.Entry(fTE).State = EntityState.Modified;
         db.SaveChanges();
         return(Json("Edit successful"));
     }
     return(Json("Unable to edit user!"));
 }
Example #3
0
        public ActionResult Create([Bind(Include = "ID,NRIC,UserID,FullName,Email,Contact")] FTE fTE)
        {
            if (ModelState.IsValid)
            {
                db.FTEs.Add(fTE);
                db.SaveChanges();
                return(Json("User created successful"));
            }

            return(Json("Unable to create account"));
        }
Example #4
0
        public ActionResult Details(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            FTE fTE = db.FTEs.Find(id);

            if (fTE == null)
            {
                return(Json("User does not exist in database!"));
            }
            return(Json(fTE));
        }
Example #5
0
        ///////////////////////////
        ///////////////////////////         EDITING EMPLOYEES
        ///////////////////////////


        private void buttonEdit_Click(object sender, EventArgs e)
        {
            int selected = getSelectedIdx(dataGridViewEmp, "idEmployee");

            toUpdateEmployee = data.Employees.SingleOrDefault(x => x.idEmployee == selected);
            toUpdateUser     = data.Users.SingleOrDefault(x => x.idUser == toUpdateEmployee.idUser);
            toUpdateFTE      = data.FTEs.SingleOrDefault(x => x.idEmployee == selected);

            textBoxName.Text    = toUpdateEmployee.name;
            textBoxSurname.Text = toUpdateEmployee.surname;
            textBoxLogin.Text   = toUpdateUser.login;


            buttonAdd.Enabled    = false;
            buttonEdit.Enabled   = false;
            buttonDelete.Enabled = false;
            buttonSave.Visible   = true;
            buttonSave.Enabled   = true;
            buttonCancel.Visible = true;
            buttonCancel.Enabled = true;
            buttonReset.Visible  = true;
            buttonReset.Enabled  = true;
        }
Example #6
0
        //////////////////////////////////
        //////////////////////////////////                  ADDING EMPLOYEES
        //////////////////////////////////

        private void buttonAdd_Click(object sender, EventArgs e)
        {
            if (textBoxName.Text != "Name" && textBoxSurname.Text != "Surname" && textBoxLogin.Text != "Login")
            {
                //ComboBoxJobContract
                string comboContractVal = ((KeyValuePair <string, string>)comboBoxContract.SelectedItem).Value;
                //ComboBoxFrenchLevel
                string comboFrenchVal = ((KeyValuePair <string, string>)comboBoxFrenchLvl.SelectedItem).Value;
                //ComboBoxPermission
                string comboPermVal = ((KeyValuePair <string, string>)comboBoxPermission.SelectedItem).Value;
                //ComboBoxPermission
                string comboTeamVal = ((KeyValuePair <string, string>)comboBoxTeam.SelectedItem).Value;
                //ComboBoxFTE
                string comboFTE = ((KeyValuePair <string, string>)comboBoxFTE.SelectedItem).Value;

                ////////////////////////////////////////// USER
                User user = new User();
                user.login      = textBoxLogin.Text;
                user.password   = PasswordHash.getHash("Password1234");
                user.permission = comboPermVal;

                data.Users.InsertOnSubmit(user);
                try { data.SubmitChanges(); } catch (System.Data.SqlClient.SqlException ex) { Console.WriteLine(ex); }

                ///////////////////////////////////////// EMPLOYEE
                Employee employee = new Employee();
                employee.name        = textBoxName.Text;
                employee.surname     = textBoxSurname.Text;
                employee.jobContract = comboContractVal;
                employee.frenchlvl   = comboFrenchVal;
                //idTeam
                if (comboTeamVal == "Channels")
                {
                    employee.idTeam = 2;
                }
                else
                {
                    employee.idTeam = 1;
                }
                //idUser
                var newUserId = (from users in data.Users
                                 orderby users.idUser descending
                                 select users.idUser).First();
                employee.idUser = newUserId;
                //independent
                if (checkBoxIndependent.Checked)
                {
                    employee.independent = true;
                }
                else
                {
                    employee.independent = false;
                }

                data.Employees.InsertOnSubmit(employee);
                try { data.SubmitChanges(); } catch (System.Data.SqlClient.SqlException ex) { Console.WriteLine(ex); }

                /////////////////////////////////     FTE

                FTE newFte = new FTE();

                ///// idEmployee
                var FTEEmp = (from emp in data.Employees
                              orderby emp.idEmployee descending
                              select emp.idEmployee).First();
                newFte.idEmployee = FTEEmp;

                /////// dimension
                if (comboFTE == "1")
                {
                    newFte.dimension = 1;
                }
                else if (comboFTE == "0.8")
                {
                    newFte.dimension = 0.8;
                }
                else if (comboFTE == "0.6")
                {
                    newFte.dimension = 0.6;
                }
                data.FTEs.InsertOnSubmit(newFte);
                try { data.SubmitChanges(); } catch (System.Data.SqlClient.SqlException ex) { Console.WriteLine(ex); }

                loadEmployees();
            }
        }
        private void buttonSave_Click(object sender, EventArgs e)
        {
            toUpdateUser     = data.Users.SingleOrDefault(x => x.idUser == this.loggedUser.idUser);
            toUpdateEmployee = data.Employees.SingleOrDefault(x => x.idUser == this.loggedUser.idUser);
            toUpdateFTE      = data.FTEs.SingleOrDefault(x => x.idEmployee == toUpdateEmployee.idEmployee);

            if (textBoxName.Text != toUpdateEmployee.name && textBoxName.Text != "")
            {
                toUpdateEmployee.name = textBoxName.Text;
            }
            if (textBoxSurname.Text != toUpdateEmployee.surname && textBoxSurname.Text != "")
            {
                toUpdateEmployee.surname = textBoxSurname.Text;
            }

            //ComboBoxJobContract
            string comboContractVal = ((KeyValuePair <string, string>)comboBoxContract.SelectedItem).Value;
            //ComboBoxFrenchLevel
            string comboFrenchVal = ((KeyValuePair <string, string>)comboBoxFrenchLvl.SelectedItem).Value;

            //ComboBoxPermission
            string comboTeamVal = ((KeyValuePair <string, string>)comboBoxTeam.SelectedItem).Value;
            //ComboBoxFTE
            string comboFTE = ((KeyValuePair <string, string>)comboBoxFTE.SelectedItem).Value;


            /////////////////////////////////     FTE
            /////// dimension
            if (comboFTE == "1")
            {
                toUpdateFTE.dimension = 1;
            }
            else if (comboFTE == "0.8")
            {
                toUpdateFTE.dimension = 0.8;
            }
            else if (comboFTE == "0.6")
            {
                toUpdateFTE.dimension = 0.6;
            }

            /////////////////////////////// Employee
            toUpdateEmployee.frenchlvl   = comboFrenchVal;
            toUpdateEmployee.jobContract = comboContractVal;
            toUpdateEmployee.jobContract = comboContractVal;
            //idTeam
            if (comboTeamVal == "Channels")
            {
                toUpdateEmployee.idTeam = 1;
            }
            else
            {
                toUpdateEmployee.idTeam = 2;
            }

            try { data.SubmitChanges(); } catch (Exception ex) { Console.WriteLine(ex); }
            labelCheck.Text = "CHANGED !!";

            if (textBoxPassword.Text != "" && textBoxRepassword.Text != "" && textBoxPassword.Text != "Password" && textBoxRepassword.Text != "Re-Password")
            {
                if (textBoxPassword.Text.Equals(textBoxRepassword.Text))
                {
                    toUpdateUser.password = PasswordHash.getHash(textBoxPassword.Text);
                    try { data.SubmitChanges(); } catch (Exception ex) { Console.WriteLine(ex); }
                    labelCheck.Text = "CHANGED !!";
                }
                else
                {
                    labelCheck.Text = "Passwords are different";
                }
            }
        }