/** * Inserts the given glist. * Throws a new NullReferenceException() if glist is null. * Throws a new DuplicateNameException() if glist is equal to another GList belonging to * the same user, or if glist has the same name as another GList belonging to the same user. * Throws a new ArgumentException() if glist.Id is equal to the id of any other GList in the database. * Returns the inserted GList. **/ public GList InsertList(GList glist) { if (glist == null) { throw new NullReferenceException(); } IEnumerable <GList> allLists = GetAllLists(); IEnumerable <GList> userLists = allLists.Where(g => g.AccountId == glist.AccountId); foreach (GList groceryList in userLists) { if (glist.Equals(groceryList)) { throw new DuplicateNameException(); } else if (glist.ListName.Equals(groceryList.ListName)) { throw new DuplicateNameException(); } } if (allLists.Any(g => g.Id == glist.Id)) { throw new ArgumentException(); } _gListAccessor.Insert(glist); return(glist); }