Beispiel #1
0
        public static object Create(SessionInfo sessioninfo, MA_USER record, int intCheckAD)
        {
            try
            {
                UserBusiness _userBusiness = new UserBusiness();
                if (intCheckAD == 1)
                {
                    bool validUser = LDAPHelper.UserExists(record.USERCODE);
                    if (!validUser)
                        return new { Result = "ERROR", Message = "User is not exist."};
                }

                record.ID = Guid.NewGuid();
                record.DEPARTMENT = record.DEPARTMENT.ToUpper();
                record.NAME = record.NAME.ToUpper();
                record.USER_OPICS = record.USER_OPICS.ToUpper();
                record.USERCODE = record.USERCODE.ToUpper();
                record.ISACTIVE = record.ISACTIVE == null || !record.ISACTIVE.HasValue ? false : true;
                record.ISLOCKED = record.ISLOCKED == null || !record.ISACTIVE.HasValue ? false : true;
                record.LOG.INSERTDATE = DateTime.Now;
                record.LOG.INSERTBYUSERID = sessioninfo.CurrentUserId;
                var addedStudent = _userBusiness.CreateUser(sessioninfo, record);
                return new { Result = "OK", Record = addedStudent };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", Message = ex.Message };
            }
        }
Beispiel #2
0
        public MA_USER CreateUser(SessionInfo sessioninfo, MA_USER user)
        {
            using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
            {
                var checkDuplicate = unitOfWork.MA_USERRepository.GetByUserCode(user.USERCODE);
                if (checkDuplicate != null)
                    throw this.CreateException(new Exception(), Messages.DUPLICATE_DATA);
                LogBusiness logBusiness = new LogBusiness();
                unitOfWork.DA_LOGGINGRepository.Add(logBusiness.CreateLogging(sessioninfo, user.ID, LogEvent.USER_AUDIT.ToString(), LookupFactorTables.MA_USER, "User", new { }));
                unitOfWork.MA_USERRepository.Add(user);
                unitOfWork.Commit();
            }

            return user;
        }
Beispiel #3
0
        public MA_USER UpdateUser(SessionInfo sessioninfo, MA_USER user)
        {
            using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
            {
                var checkDuplicate = unitOfWork.MA_USERRepository.GetAll().FirstOrDefault(p => p.USERCODE.ToLower() == user.USERCODE.ToLower() && p.ID != user.ID);
                if (checkDuplicate != null)
                    throw this.CreateException(new Exception(), Messages.DUPLICATE_DATA);

                var foundUser = unitOfWork.MA_USERRepository.GetAll().FirstOrDefault(p => p.ID == user.ID);
                if (foundUser == null)
                    throw this.CreateException(new Exception(), Messages.DATA_NOT_FOUND);
                else
                {
                    LogBusiness logBusiness = new LogBusiness();
                    var oldRecord = new {

                        DEPARTMENT = foundUser.DEPARTMENT, ISACTIVE = foundUser.ISACTIVE
                        , ISLOCKED = foundUser.ISLOCKED, NAME = foundUser.NAME
                        , USERCODE = foundUser.USERCODE, USER_OPICS = foundUser.USER_OPICS
                        , USER_PROFILE = foundUser.MA_USER_PROFILE.LABEL
                    };
                    var newRecord = new
                    {
                        DEPARTMENT = user.DEPARTMENT, ISACTIVE = user.ISACTIVE
                        , ISLOCKED = user.ISLOCKED, NAME = user.NAME
                        , USERCODE = user.USERCODE, USER_OPICS = user.USER_OPICS
                        , USER_PROFILE = unitOfWork.MA_USER_PROFILERepository.All().FirstOrDefault(p=> p.ID== user.USER_PROFILE_ID).LABEL
                    };

                    var log = logBusiness.UpdateLogging(sessioninfo, foundUser.ID, LogEvent.USER_AUDIT.ToString(), LookupFactorTables.MA_USER, oldRecord, newRecord);
                    if (log != null) unitOfWork.DA_LOGGINGRepository.Add(log);
                    foundUser.ID = user.ID;
                    foundUser.DEPARTMENT = user.DEPARTMENT;
                    foundUser.ISACTIVE = user.ISACTIVE;
                    foundUser.ISLOCKED = user.ISLOCKED;
                    foundUser.LOG.MODIFYBYUSERID = user.LOG.MODIFYBYUSERID;
                    foundUser.LOG.MODIFYDATE = user.LOG.MODIFYDATE;
                    foundUser.NAME = user.NAME;
                    foundUser.USERCODE = user.USERCODE;
                    foundUser.USER_OPICS = user.USER_OPICS;
                    foundUser.USER_PROFILE_ID = user.USER_PROFILE_ID;

                    unitOfWork.Commit();

                }
            }

            return user;
        }
 public static object UpdateUser(MA_USER record)
 {
     return UserUIP.Update(SessionInfo, record
                         , Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings[AppSettingName.CHECK_AD_USER]));
 }