-
-
Save eestein/d5ecd4f598869651cc3158fe401b5194 to your computer and use it in GitHub Desktop.
Revisions
-
eestein revised this gist
Aug 11, 2017 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -5,15 +5,16 @@ public ProviderManagerProfileViewModel Update(ProviderManagerProfileViewModel da 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 { -
eestein created this gist
Aug 11, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ public ProviderManagerProfileViewModel Update(ProviderManagerProfileViewModel data) { var providerManagerProfile = Context.GetRepository<ProviderManagerProfile>().GetById(data.Id); providerManagerProfile.User.Email = data.Email; providerManagerProfile.User.Name = data.Name; 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))) { Context.Delete(profile); } foreach (var storeId in data.StoresIds.Where(id => !mutualIds.Contains(id))) { providerManagerProfile.User.Profiles.Add(Context.Add(new ProviderManagerProfile { StoreId = storeId })); } Context.Save(false); return providerManagerProfile.Format(); }