Esempio n. 1
0
        private void CheckCollectionThenAddCollectionAndTuneCollection(Tune tune)
        {
            var user        = GetCurrentUser();
            var collections = _collectionRepository.GetCollectionsByUserId(user.Id);
            List <Collection> currentCollection = collections.Where(c => (c.Name == tune.Tuning) || (c.Name == $"{tune.Key}/{tune.Tuning}")).ToList();

            if (currentCollection.Count() == 0)
            {
                //collection doesn't exist
                //add Collection
                string collName = "";
                if (tune.Tuning == "Standard")
                {
                    collName = tune.Key;
                }
                else
                {
                    collName = $"{tune.Key}/{tune.Tuning}";
                }

                var collToAdd = new Collection()
                {
                    UserProfileId = user.Id,
                    Name          = collName
                };
                Collection newColl = _collectionRepository.saveCollection(collToAdd);

                var tc = new TuneCollection()
                {
                    CollectionId = newColl.Id,
                    TuneId       = tune.Id
                };

                _tuneRepo.AddTuneCollection(tc);
            }
            else
            {
                //collection exists
                //add TC
                var tc = new TuneCollection()
                {
                    CollectionId = currentCollection[0].Id,
                    TuneId       = tune.Id
                };

                _tuneRepo.AddTuneCollection(tc);
            }
        }
Esempio n. 2
0
 public void AddTuneCollection(TuneCollection tc)
 {
     _context.Add(tc);
     _context.SaveChanges();
 }