public DUOJU_IDENTIFIERS GenerateIdentifier(IdentifierTypes type, DateTime expiresTime, IList <KeyValuePair <string, string> > settings, int operatorId) { DateTime createTime; string identifierNO; while (true) { createTime = DateTime.Now; identifierNO = string.Format( "{0}{1}", ((int)type).ToString().PadLeft(2, '0'), WeChat.ConvertTimeStamp(createTime) ); if (IdentifierRepository.IsIdentifierNOUnique(identifierNO)) { break; } Thread.Sleep(1); } var identifier = new DUOJU_IDENTIFIERS { IDENTIFIER_TYPE = (int)type, IDENTIFIER_NO = identifierNO, EXPIRES_TIME = expiresTime, STATUS = (int)IdentifierStatuses.NEW, CREATE_BY = operatorId, CREATE_TIME = createTime, LAST_UPDATE_BY = operatorId, LAST_UPDATE_TIME = DateTime.Now }; if (settings != null && settings.Count > 0) { foreach (var setting in settings) { identifier.DUOJU_IDENTIFIER_SETTINGS.Add(new DUOJU_IDENTIFIER_SETTINGS { SETTING_CODE = setting.Key, SETTING_VALUE = setting.Value, CREATE_BY = operatorId, CREATE_TIME = DateTime.Now, LAST_UPDATE_BY = operatorId, LAST_UPDATE_TIME = DateTime.Now }); } } IdentifierRepository.AddIdentifier(identifier); IdentifierRepository.SaveChanges(); return(identifier); }
public void AddIdentifier(DUOJU_IDENTIFIERS identifier) { DBEntities.DUOJU_IDENTIFIERS.Add(identifier); }