public int Create(FormCollection form)
        {
            User newUser = new User();
            Employee newEmployee = new Employee();

            newUser.Email = form["user.Email"];
            newUser.GroupId = int.Parse(form["groups"]);
            newUser.Password = form["user.Password"];
            newUser.ConfirmPassword = form["user.ConfirmPassword"];

            newEmployee.FirstName = form["user.Employee.FirstName"];
            newEmployee.LastName = form["user.Employee.LastName"];
            newEmployee.Manager = int.Parse(form["Managers"]);
            newEmployee.CNP = form["user.Employee.CNP"];

            newUser.Employee = newEmployee;

            UserRepository userRepo = new UserRepository();
            userRepo.addUser(newUser);
            if (userRepo.Save())
            {
                return 1;
            }

            return 0;
        }
        public UserViewModel()
        {
            UserRepository usersRepo = new UserRepository();
            EmployeeRepository employeeRepo = new EmployeeRepository();

            Users = usersRepo.getAllUsers();
            Employees = employeeRepo.getAllEmployees();
        }
 public int Delete(int id)
 {
     UserRepository userRepo = new UserRepository();
     userRepo.removeUserById(id);
     if (userRepo.Save())
     {
         return 1;
     }
     return 0;
 }
 private void LoadUser(int id)
 {
     UserRepository userRepo = new UserRepository();
     user = userRepo.getUserById(id);
 }
        public string Edit(FormCollection editedUser)
        {
            if (!ModelState.IsValid)
            {
                return "You had some errors in the form.";

            }
            UserRepository userRepo = new UserRepository();
            User user = new User();
            Employee employee = new Employee();

            user.Id   = int.Parse(editedUser["user.id"]);
            user.Email= editedUser["user.Email"];
            employee.FirstName = editedUser["user.Employee.FirstName"];
            employee.LastName = editedUser["user.Employee.LastName"];
            employee.CNP = editedUser["user.Employee.CNP"];

            if (!string.IsNullOrEmpty(editedUser["Managers"]))
            {
                employee.Manager = int.Parse(editedUser["Managers"]);
            }

            user.GroupId = int.Parse(editedUser["groups"]);
            user.Employee = employee;

            userRepo.updateUser(user);

            if (!userRepo.Save())
            {
                return "User failed to updated. Try again later.";
            }

            return "User successfully updated.";
        }
 public ActionResult Details(int id)
 {
     UserRepository userRepo = new UserRepository();
     return PartialView("_UserDetails", userRepo.getUserById(id));
 }