public async Task <bool> UpdateStore(StoreViewModel model) { try { var currentStore = await _context.Stores.FirstOrDefaultAsync(s => s.StoreId == model.Id); currentStore.Name = model.StoreName; currentStore.Contact = model.Contact; currentStore.IsActive = model.IsActive; currentStore.DeliveryFee = model.DeliveryFee; currentStore.Address = model.Address; // might need to break out address in a separate query currentStore.ServiceType = model.ServiceType; currentStore.Commission = model.Commission; List <AppUserStore> updates = new List <AppUserStore>(); foreach (var owner in model.GetStoreOwners()) { updates.Add(new AppUserStore { AppUserId = owner.Id, StoreId = currentStore.StoreId }); } var query = _context.AppUserStores.Where(x => x.StoreId == currentStore.StoreId).ToList(); _context.RemoveRange(query); _context.AppUserStores.AddRange(updates); await _context.SaveChangesAsync(); return(true); }catch (Exception message) { Console.WriteLine(message); return(false); } }