Example #1
0
        public int Save(EmployeeModel obj)
        {
            CU_Employee oldObj  = new CU_Employee();
            CU_Employee oldObj2 = new CU_Employee();

            if (obj.ID > 0)
            {
                oldObj2 = GetByID((int)obj.ID);
                oldObj  = oldObj2.Clone();
            }

            // decrypt password to prevent double ecryption
            //    string decryptedPassword = DataProtection.Decrypt(obj.Password);
            //   if (!decryptedPassword.Contains("The input is not"))

            //    obj.Password = string.IsNullOrEmpty(obj.Password) ? null : contract_Extention.testDecrypt(obj.Password);
            if (string.IsNullOrEmpty(obj.Password) != null)
            {
                string strsalt = string.Empty;
                obj.Password = hashSaltProtection.GeneratePasswordHash(obj.Password, out strsalt);
                obj.Salt     = strsalt;
            }
            var data = Mapper.Map <EmployeeModel, CU_Employee>(obj);

            int?parentLogId = 0;

            if (obj.ID > 0)
            {
                oldObj2.Name     = data.Name;
                oldObj2.Mobile   = data.Mobile;
                oldObj2.IsActive = data.IsActive;

                _CU_EmployeeRepository.Save(oldObj2);
                _unitOfWork.Submit();
                parentLogId = _logService.Update(data.ID, DataServiceArabicResource.User, oldObj, oldObj2, obj.UserId.Value, obj.ActionName);
            }
            else
            {
                _CU_EmployeeRepository.Save(data);
                _unitOfWork.Submit();
                obj.ID = data.ID;

                parentLogId = _logService.Insert(data.ID, DataServiceArabicResource.User, obj, obj.UserId.Value, obj.ActionName.ToLower().Replace("add", "edit").Replace("0", data.ID.ToString()));
            }

            int?logId;

            if (obj.UserRoles != null)
            {
                new CU_Employee_RoleProgramService().Save(obj.UserRoles, data.ID, parentLogId, out logId, obj.UserId.Value, "AddEdit");
            }
            return((int)data.ID);
        }
        public void ChangePassword(int id, string NewpassWord)
        {
            CU_Employee emp = _Employee.Get(x => x.ID == id).First();
            //  emp.Password = DataProtection.Encrypt(NewpassWord);
            string strsalt = string.Empty;

            emp.Password = hashSaltProtection.GeneratePasswordHash(NewpassWord, out strsalt);
            emp.Salt     = strsalt;
            _Employee.Update(emp);
            _unitOfWork.Submit();

            CU_Employee beforUpdate = emp.Clone();

            if (emp != null)
            {
                _logService.ChangePassword(emp.ID);
            }
        }