Graphing directional user assignments - c#

I have a DB table which records changes made to orders. One of the properties on the order object is the ID of the administrator. When an administrator goes out-of-office they have the option of assigning a replacement; the replacement can then assign someone to replace themselves, who can then assign a replacement...
Each time a replacement is assigned the order is updated and an audit trail is created in a DB table named audit_log.
When an administrator returns to work they can remove their replacement, which should then cause their orders to be reassigned to them. This seems a simple problem but I'm having trouble with the logic behind deciding which orders should be reassigned. For example, take a look at the image below...
Now look what happens if Admin 1 returns...
...so far so good, but if Admin 2 then returns...
...Admin 2 would be mistakenly reassigning an order from Admin 1 because the audit log shows that Admin 2 had previously reassigned it to Admin 3 prior to leaving the office. But that order shouldn't be reassigned from Admin 1 to Admin 2 - it belongs to Admin 1 and Admin 1 is not out-of-office.
Consider the scenario where the order gets reassigned through 5 different administrators, then Admin 3 returns and reclaims the order from Admin 5; if Admin 4 then returns they should not be assigned the order, but if Admin 1 or Admin 2 returns then they should reclaim the order from Admin 3.
What this needs is a way of graphing the changes in assignment, then detecting which orders have been assigned ahead of a user but not behind a user, where...
ahead of = a user who is to the right of a context user in the above images (Admin 3 being ahead of Admin 2)
behind = a user who is to the left of a context user in above images (Admin 1 being behind Admin 2)
...but I just don't know how to build this? Are there any well-known algorithms or patterns from building such a graph, and any pointers as to how to implement such in C#?
Some additional information: The records in the audit_log DB table also have id and recorded (DateTime2) fields, so they can be retrieved in chronological order.

Related

Adding a "entered by" field to crud operations

I have a simple CRUD app in .net core with an Admin role and the rest of the users are normal users with no role. I wanted to make the Index of the crud data have the user next to each input that submitted the data while signed in. So say user1#app.com entered data into the database - I want their email to show up next to that data entry in the Index view. That way every user can have their own data tracked.
I have been searching questions and googling forever and maybe I just don't know how to word it correctly. If someone could point me in the right direction I would appreciate it. Something like below..
Food item
Price
Entered by
Apple
1.00
user1#app.com
Pear
2.00
user2#app.com
When registering with a record with the following code, you can obtain and save the user email.
System.Web.HttpContext.Current.User.Identity.Name

Google Admin API - Moving User to Different OU

I've seen code snippets and answers for setting a user to an Org Unit (OU) during user creation, but nothing regarding moving a user from one OU to another after it's been created.
NOTE: Prior to this I retrieved the user I wanted to modify, which is what the user variable refers to.
user.OrgUnitPath = "/NLWC";
var updateResult = await _service.Users.Update(user, user.Id).ExecuteAsync();
updateResult returns a User object. When I view the OrgUnitPath in the returned user I view the desired OU path (and also, when I query that same user in the future I get the same result).
But when I view the user in the Gsuite admin console, the OU hasn't changed.
In fact, I manually moved the user to the OU, and queried the user object again. After manually moving it, the OrgUnitPath is still the same.
Additionally, I queried the Org Units to verify I have the right path, and it shows the following:
I can't understand why it's not moving the user to the right OU, what am I missing?

Access the same data by more than 1 client on almost the same time

Good day all,
I am work on C# .net 4.0 framework, and database is microsoft SQL server 2008 R2.
There is a system to let user do gift redemption. When User click on the "redeem" button, system will :
check on the gift inventory first before update customer_gift table,
and update the gift_inventory table for the particular gift.
If the inventory is less than 0, then it will prompt error message to tell user that the gift is already finish, and then cancel the redemption process.
There is a problem happen in the following condition :
Gift A only have 1 quantity in inventory now.
Customer Jack click on "redeem" button at 2013-11-11 09:22:27.780.
Customer Jess click on "redeem" button at 2013-11-11 09:22:27.497.
The different time they click on "redeem" button is only 0.0283 seconds.
Thus, maybe the different time is too short, both of them was successful redeem the gift because, before the system (first customer) update the gift_inventory table, the system (second customer) already get the data from inventory (Gift A), thus, system still let second customer to proceed because the inventory is still equal to 1.
I have think out of a way to solve this problem, which is describe as follow :
Create a new column for the gift_inventory table, name lock, with data type Boolean . When customer clicked on the redeem button, and before the system check the gift inventory, set the Boolean to true. Thus, if the second customer, try to access to the gift inventory, and found that the lock = true, then system will wait for 1 seconds and then try to access again, until the lock = false, then only access and get the inventory data.
However, I dun think this is a good solution. I think this may cause the database become slow.
Any idea and suggestion?
I think you can achieve this just by doing each update in a transaction and by using row locking in database.
Read more here:
Transactions
http://technet.microsoft.com/en-us/library/jj856598.aspx
Locking
http://technet.microsoft.com/en-us/library/aa213039(v=sql.80).aspx

Which Schema change scenario?

My current schema looks like the following:
ID | DisplayVal
-- ----------
1 1-H-3
2 2-H-3
3 3-J-4
In the above, the ID field is an IDENTITY INT field which is also used as and end user account Id. The DisplayVal is what they see on the screen.
A new client has provided their own Account Id values, but they are alpha-numeric, so they can't just go into the IDENTITY field. Here are my scenarios: I am looking for a scenario that would offer the best maintainability, end user experience, magnitude and impact of changes and testing/QA impact.
My first scenario was to add an Account Number column that would be a VARCHAR(x) and accommodate all types of Account Numbers. It would look like this:
ID | DisplayVal | AccountNumber
-- ---------- -------------
1 1-H-3 1
2 2-H-3 2
3 3-J-4 3
4 h389 h389
5 h-400-x h400
In the above, in the case of the first client, the seeded Identity which is the Account Id would be copied into the Account Number, but for the other client, there would still be a seeded Identity created, but their Account Number would be different and it may or may not match the Display Value.
My second scenario was to not add any columns and for clients that provide an Account Number, I would turn off IDENTITY INSERT and insert the new Id's and then turn identity insert back on. If a client did not provide an Account Number, I would auto-generate one, obviously trying to avoid collisions.
The third scenario was basically to leave the new Account Number as a legacy Account Number and create new identity values for all new records. This would require the end-user to become familiar with a new Account Number. It is probably the easiest, but not sure if there are any downsides.
If there is another scenario you know that would work well in this case, let me know.
You should not use business keys, like account id, as identity. Create a new id column and populate it either using an autoincrement field or a guid. Your users or other systems that interact with your system should not know/depend on this value.

Adding a new field or adding a new value?

If i have a field in my db which clarify the type of the application .
takes two values 0 or 1
0 for web app and 1 for win app
and now there is some requirement in my business:
There are some win applications available to all users and some of
them belong to specific users .
What 's the best solution to handle this case .
adding new field to state whether it's public or private
or just adding new value to the same field say 2 to state it's private win app
If you haven't already it would probably be best to slip in a user, role, permission based security model to the database/system, thereby giving you the ability to specify a group of users that have access to a particular application, whether it be web or windows based
I'd say add a new column next to your AppId called PublicIndicatior
Oh and be sure to have a lookup table so people can see what 0 or 1 means, and foreign key it to your data table
Lookup Table:
AppTypeId, AppTypeDescription
0, WebApp
1, WinApp
Data Table:
Id, AppTypeId, PublicIndicator
1,0,1
etc
As Pope suggested above (I +1 him), the best scenario is to add in a new user table (or tables for roles etc if possible) and then link to that through either a new foreign key, or using the appid (assuming it is on your table and unique). Then when the boss comes back 3 weeks later and say, "that's great, but now can we restrict App99 to just the Accounts Dept" you are not going back to the drawing board.

Categories

Resources