public static void Set(OwnerStatusHistory data, LcDatabase database = null) { using (var db = new LcDatabase(database)) { db.Execute(sqlSet, data.userID, data.ownerStatusID, data.ownerStatusChangedDate, data.ownerStatusChangedBy ); } }
/// <summary> /// Set the user OwnerStatus in database, only if different from current /// one, and saving a status history entry. /// </summary> /// <param name="userID"></param> /// <param name="status"></param> public static void Set(Owner owner) { var currentOwner = UserProfile.Get(owner.userID).owner; if (currentOwner.status != owner.status) { var allowChange = currentOwner.CanTransitionTo(owner.status); if (allowChange) { // Save on database, with a new entry at the status history var his = new OwnerStatusHistory { userID = owner.userID, ownerStatusID = owner.statusID, ownerStatusChangedDate = DateTime.Now, ownerStatusChangedBy = "sys" }; using (var db = new LcDatabase()) { var trans = db.Connection.BeginTransaction(); OwnerStatusHistory.Set(his, db); db.Execute(@" UPDATE Users SET OwnerStatusID = @1 WHERE UserID = @0 -- First time user enters 'active' status, -- set the anniversary date. -- Impl: we check if is active:2 and inside set date as current only if null IF @1 = 2 begin UPDATE Users SET OwnerAnniversaryDate = getdate() WHERE UserID = @0 AND OwnerAnniversaryDate is null END ", owner.userID, owner.statusID); trans.Commit(); } } } }