// insert all object members as a new row in table // links: // docLink: http://sql2x.org/documentationLink/75aad010-e6aa-4f19-a6e5-597456aa20d8 public void Insert(CrudeDefaultUserContract contract) { var data = new CrudeDefaultUserData(); ContractToData(contract, data); data.Insert(); }
// insert all object members as a new row in table, in a transaction // the transaction and or connection state is not changed in any way other than what SqlClient does to it. // it is the callers responsibility to commit or rollback the transaction // links: // docLink: http://sql2x.org/documentationLink/542f9458-c3b9-4edf-8575-0870086f3a7f public void Insert(CrudeDefaultUserContract contract, SqlConnection connection, SqlTransaction transaction) { var data = new CrudeDefaultUserData(); ContractToData(contract, data); data.Insert(connection, transaction); }
/// <summary> /// Login a user and log the activity /// </summary> /// <param name="userCode">IP address will be resolved to whois netname, valid usercode stays</param> /// <returns>Internal user id</returns> public Guid Login( string userCode, bool overrideUserName ) { CrudeDefaultUserData defaultUser = new CrudeDefaultUserData(); try { defaultUser.FetchByDefaultUserName(userCode); // insert if not existing if (defaultUser.DefaultUserId == Guid.Empty) { defaultUser.DefaultUserId = new Guid(); defaultUser.DefaultUserCode = userCode; // resolve net-name if user code appears to be an ip address IPAddress ipAddress; if (IPAddress.TryParse(userCode, out ipAddress)) { defaultUser.DefaultUserName = ResolveNetnameFromIpV4(userCode); // use ip user code if no net-name found if (string.IsNullOrEmpty(defaultUser.DefaultUserName)) { defaultUser.DefaultUserName = userCode; } } else { // not an ip address, username is usercode defaultUser.DefaultUserName = userCode; } defaultUser.DefaultStateRcd = DefaultStateRef.Created; defaultUser.DateTime = DateTime.UtcNow; defaultUser.CreatedByDefaultUserId = new Guid("FFFFFFFF-5555-5555-5555-FFFFFFFFFFFF"); defaultUser.Insert(); AddActivity( defaultUser.DefaultUserId, DefaultUserActivityTypeRef.Login, "New user: "******"Internal" ); } else { // resolve net-name if user name appears to be an ip address // or an averride is asked for IPAddress ipAddress; if (IPAddress.TryParse(defaultUser.DefaultUserName, out ipAddress) || overrideUserName ) { string netName = ResolveNetnameFromIpV4(userCode); // use new net-name if found if (!string.IsNullOrEmpty(netName)) { // a new net name was found, use that instead of ip address defaultUser.DefaultUserName = netName; defaultUser.DefaultStateRcd = DefaultStateRef.Updated; defaultUser.DateTime = DateTime.UtcNow; defaultUser.Update(); AddActivity( defaultUser.DefaultUserId, DefaultUserActivityTypeRef.Login, "Resolved user name: " + defaultUser.DefaultUserName + " from IP address: " + userCode, "Internal" ); } } } AddActivity( defaultUser.DefaultUserId, DefaultUserActivityTypeRef.Login, defaultUser.DefaultUserName, "Internal" ); } catch (Exception ex) { // todo, what happens with WCF here? throw new Exception("Login failed", ex); } return(defaultUser.DefaultUserId); }