Beispiel #1
0
        public ActionResult Create(NewEmployeeViewModel model)
        {
            BLLProfile _profile = new BLLProfile();

            try
            {
                if (ModelState.IsValid)
                {
                    if (_profile.NewEmployee(model, User.IDNO))
                    {
                        return RedirectToAction("Index");
                    }
                    else
                    {
                        ModelState.AddModelError("", "An error has been encountered. Please contact your System Administrator.");
                    }
                }

                NewEmployeeViewModel _newEmployee = new NewEmployeeViewModel();
                _newEmployee.Position = _profile.GetPositionTitles();
                _newEmployee.EmploymentStatus = _profile.GetEmploymentStatus();

                return View(_newEmployee);
            }
            catch
            {
                NewEmployeeViewModel _newEmployee = new NewEmployeeViewModel();
                _newEmployee.Position = _profile.GetPositionTitles();
                _newEmployee.EmploymentStatus = _profile.GetEmploymentStatus();

                ModelState.AddModelError("", "An error has been encountered. Please contact your System Administrator.");

                return View(_newEmployee);
            }
        }
Beispiel #2
0
        public bool NewEmployee(NewEmployeeViewModel model, string rowmodifiedby)
        {
            DALProfile _profile = new DALProfile();
            GenericProvider.HashStore.CustomHash _hash = new GenericProvider.HashStore.CustomHash();

            model.RegularizationDate = model.DateHired.Value.AddDays(180);

            return _profile.SaveEmployee(model, _hash.ComputeHash(model.Password), _hash.saltValue, rowmodifiedby);
        }
Beispiel #3
0
 public ActionResult Create()
 {
     NewEmployeeViewModel _newEmployee = new NewEmployeeViewModel();
     BLLProfile _profile = new BLLProfile();
     _newEmployee.Password = _profile.GeneratePassword();
     _newEmployee.Position = _profile.GetPositionTitles();
     _newEmployee.Department = _profile.GetDepartmentNames();
     _newEmployee.CivilStatus = _profile.GetCivilStatus();
     _newEmployee.EmploymentStatus = _profile.GetEmploymentStatus();
     return View(_newEmployee);
 }
Beispiel #4
0
        public bool SaveEmployee(NewEmployeeViewModel model, string passwordhash, string passwordsalt, string rowmodifiedby)
        {
            using (DataContext _context = new DataContext())
            {
                int _rowsaffected = _context.Database.ExecuteSqlCommand(
                    "pInsertEmployee @IDNO, @CardNo, @FirstName, @MiddleName, @LastName, @Position, @isActive," +
                    "@HiredDate, @EmploymentStatusId, @DepartmentId, @CivilStatusId, @RegularizationDate, @Gender, @Email, @RowModifiedBy",
                    new SqlParameter("@IDNO", model.IDNO),
                    new SqlParameter("@CardNo", model.CardNo),
                    new SqlParameter("@FirstName", model.FirstName),
                    new SqlParameter("@MiddleName", model.MiddleName),
                    new SqlParameter("@LastName", model.LastName),
                    new SqlParameter("@Position", model.PositionTitleID),
                    new SqlParameter("@isActive", model.isActive),
                    new SqlParameter("@HiredDate", model.DateHired),
                    new SqlParameter("@EmploymentStatusId", model.EmploymentStatusId),
                    new SqlParameter("@DepartmentId", model.DepartmentId),
                    new SqlParameter("@CivilStatusId", model.CivilStatusId),
                    new SqlParameter("@RegularizationDate", model.RegularizationDate),
                    new SqlParameter("@Gender", model.Gender),
                    new SqlParameter("@Email", model.Email),
                    new SqlParameter("@RowModifiedBy", rowmodifiedby));

                if (_rowsaffected == 0)
                {
                    _context.Database.Connection.Close();
                    _context.Database.Connection.Dispose();
                    return false;
                }

                _rowsaffected = _context.Database.ExecuteSqlCommand(
                    "pInsertAccess @IDNO, @PasswordHash, @PasswordSalt, @isLocked, @RowModifiedBy",
                    new SqlParameter("@IDNO", model.IDNO),
                    new SqlParameter("@PasswordHash", passwordhash),
                    new SqlParameter("@PasswordSalt", passwordsalt),
                    new SqlParameter("@isLocked", model.IsLocked),
                    new SqlParameter("@RowModifiedBy", rowmodifiedby));

                if (_rowsaffected == 0)
                {
                    _context.Database.Connection.Close();
                    _context.Database.Connection.Dispose();
                    return false;
                }

                _context.Database.Connection.Close();
                _context.Database.Connection.Dispose();
                return true;
            }
        }