-
-
Save eestein/d5ecd4f598869651cc3158fe401b5194 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ProviderManagerProfileViewModel Update(ProviderManagerProfileViewModel data) | |
{ | |
var providerManagerProfile = Context.GetRepository<ProviderManagerProfile>().GetById(data.Id); | |
providerManagerProfile.User.Email = data.Email; | |
providerManagerProfile.User.Name = data.Name; | |
var loggedUserStoresIds = LoggedUser.GetStores().Select(s => s.StoreId).ToArray(); | |
var profiles = providerManagerProfile.User.Profiles.OfType<ProviderManagerProfile>().ToArray(); | |
var mutualIds = data.StoresIds.Intersect(profiles.Select(pmp => pmp.StoreId).ToArray()); | |
foreach (var profile in profiles.Where(p => !mutualIds.Contains(p.StoreId) && loggedUserStoresIds.Contains(p.StoreId))) | |
{ | |
profile.RemovedDate = DateTime.Now; | |
} | |
foreach (var storeId in data.StoresIds.Where(id => !mutualIds.Contains(id) && loggedUserStoresIds.Contains(id))) | |
{ | |
providerManagerProfile.User.Profiles.Add(Context.Add(new ProviderManagerProfile | |
{ | |
StoreId = storeId | |
})); | |
} | |
Context.Save(false); | |
return providerManagerProfile.Format(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment