Let's say we have a clear method that does an update.
public void UpdateUser(UpdateUserRequest request)
{
var existing = context.Users.First(x=>x.Id == request.Id);
existing.FirstName = request.FirstName;
existing.LastName = request.LastName;
existing.EmployeeId = request.EmployeeId;
context.SaveChanges();
}
Lets say this is the method used the caller to update a user but there are a few cases.
Caller 1 is admin and therefore can update all the properties
Caller 2 is user but can update First/LastName only
Options that I have:
- Have a UserType (could be role or permission or whatever) on Request and check their type and not update EmployeeID if they are normal user introducing if condition
- Copy past and rename to UpdateNormalUser and remove EmployeeId
So I either end up with a bunch of if statements to check type or mutliple methods.
Are these the only two options, considering there might be many types of users who will only be able to update certain bits of info?