public void Put(PersonModel person) { //TODO change to match generic repository pattern. using (var db = new Repository<Person>().DataContext) { Person personToUpdate = db.People.Single(p => p.PersonId == person.PersonId); personToUpdate.PersonId = person.PersonId; personToUpdate.FirstName = person.FirstName; personToUpdate.LastName = person.LastName; personToUpdate.IsAuthorised = person.IsAuthorised; personToUpdate.IsEnabled = person.IsEnabled; personToUpdate.IsValid = person.IsValid; int[] favouriteColourIds = person.Colours.Select(cm => cm.ColourId).ToArray(); ICollection<Colour> allColours = db.Colours.ToList(); foreach (var colour in allColours) { // Add new favourite colours. if (favouriteColourIds.Contains(colour.ColourId) && personToUpdate.Colours.All(c => c.ColourId != colour.ColourId)) { personToUpdate.Colours.Add(colour); } // Remove colours which are no longer favourites. else if (!favouriteColourIds.Contains(colour.ColourId) && personToUpdate.Colours.All(c => c.ColourId == colour.ColourId)) { personToUpdate.Colours.Remove(colour); } } db.Entry(personToUpdate).State = EntityState.Modified; db.SaveChanges(); } }
public AccountRepository(Repository.EntitiesContainer context) { this.Entities = context; }
public HomeController() { bookRepository = unitOfWork.Repository<Entity>(); }
public ProductsController() { _repository = new Repository(); _productsRepository = _repository.Products; }