Esempio n. 1
0
        /// <summary>
        /// Mapping user with UserViewModel
        /// </summary>
        /// <param name="userEntity"></param>
        /// <returns></returns>
        private static UserViewModel GetUserModel(User userEntity, HasanEntities database)
        {
            if (userEntity != null)
            {
                UserViewModel model = new UserViewModel();
                model.Id = userEntity.Id;
                model.gKey = userEntity.gKey;
                model.UserTypeRef = userEntity.UserTypeRef;
                model.UserTypeName = userEntity.UserType.Name;
                model.GroupCompanyRef = userEntity.GroupCompanyRef;

                model.EMail = userEntity.EMail;
                model.Password = userEntity.Password;
                model.PIN = userEntity.PIN;
                model.Name = userEntity.Name;
                model.Surname = userEntity.Surname;
                model.ChangePasswordAtNextLogon = userEntity.ChangePasswordAtNextLogon;
                model.MailNotification = userEntity.MailNotification;
                model.Note = userEntity.Note;
                model.Sort = userEntity.Sort;
                model.Active = userEntity.Active;
                model.Deleted = userEntity.Deleted;
                return model;
            }
            else
                return null;
        }
Esempio n. 2
0
        /// <summary>
        /// Create new user
        /// </summary>
        /// <param name="model"></param>
        /// <param name="database"></param>
        /// <returns></returns>
        public static FocusConstants.FocusResultCode CreateUser(UserViewModel model, HasanEntities database)
        {
            try
            {

                if (DoesUserNameExist(model.EMail, database))
                    return FocusConstants.FocusResultCode.DuplicateUser;

                User entity = new User();
                entity.UserTypeRef = model.UserTypeRef;
                entity.GroupCompanyRef = model.GroupCompanyRef;
                entity.CustomerRef = model.CustomerRef;
                entity.FactoryRef = model.FactoryRef;
                entity.PersonRef = model.PersonRef;
                entity.EmployeeRef = model.EmployeeRef;
                entity.EMail = model.EMail;
                entity.Password = model.Password;
                entity.PIN = model.PIN;
                entity.Name = model.Name;
                entity.Surname = model.Surname;
                entity.ChangePasswordAtNextLogon = model.ChangePasswordAtNextLogon;
                entity.MailNotification = model.MailNotification;
                entity.Note = model.Note;
                entity.Sort = model.Sort;
                entity.Active = model.Active;
                entity.Deleted = false;
                database.User.Add(entity);
                database.SaveChanges();
            }
            catch (Exception ex)
            {
                Logger logger = LogManager.GetCurrentClassLogger();
                logger.ErrorException("CreateUserType", ex);
                return FocusConstants.FocusResultCode.Exception;
            }
            return FocusConstants.FocusResultCode.Success;
        }
Esempio n. 3
0
        /// <summary>
        /// Mapping userdata to UserViewModel
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="loadClass"></param>
        /// <returns></returns>
        private static UserViewModel GetUserDTO(User entity, bool loadClass)
        {
            try
            {
                if (entity != null)
                {
                    UserViewModel model = new UserViewModel();
                    model.Id = entity.Id;
                    model.gKey = entity.gKey;
                    model.EMail = entity.EMail;
                    model.Name = entity.Name;
                    model.Note = entity.Note;
                    model.Sort = entity.Sort;
                    model.Active = entity.Active;
                    model.Deleted = entity.Deleted;
                    return model;
                }
                else
                    return null;
            }
            catch (Exception ex)
            {
                Logger logger = LogManager.GetCurrentClassLogger();
                logger.ErrorException("GetUserDTO", ex);
                throw ex;

            }
        }