Skip to content

Instantly share code, notes, and snippets.

@eestein
Last active August 11, 2017 02:34
Show Gist options
  • Save eestein/d5ecd4f598869651cc3158fe401b5194 to your computer and use it in GitHub Desktop.
Save eestein/d5ecd4f598869651cc3158fe401b5194 to your computer and use it in GitHub Desktop.
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