コード例 #1
0
ファイル: Program.cs プロジェクト: GCarrell/MusicManager
        public (string returnMessage, string passOrFail) AddUser(string userName, string password)
        {
            using (var db = new MusicManagerContext())
            {
                var validationResult = inputValidation(userName, password);

                if (validationResult.passOrFail == "fail")
                {
                    return(validationResult);
                }

                var findUser =
                    db.Users.Where(c => c.UserName == userName);

                if (findUser.Count() > 0)
                {
                    return("This username is already in use.", "fail");
                }

                else
                {
                    var newUser = new User
                    {
                        UserName = userName,
                        Password = password,
                    };
                    db.Users.Add(newUser);
                    db.SaveChanges();
                    return("User Successfully Created.", "pass");
                }
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: GCarrell/MusicManager
 public void DeleteFavouriteTab()
 {
     using (var db = new MusicManagerContext())
     {
         var faveForDeletion = db.Favourites.Where(c => c.TabId == CurrentTab.TabId && c.UserId == User.UserId);
         db.Favourites.RemoveRange(faveForDeletion);
         db.SaveChanges();
     }
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: GCarrell/MusicManager
        public string LikeDislikeTab(int rating)
        {
            using (var db = new MusicManagerContext())
            {
                var findExistingLike = db.Ratings.Where(c => c.UserId == User.UserId && c.TabId == CurrentTab.TabId).FirstOrDefault();

                if (findExistingLike is null)
                {
                    var newRating = new Rating
                    {
                        TabId   = CurrentTab.TabId,
                        UserId  = User.UserId,
                        Rating1 = rating
                    };
                    db.Ratings.Add(newRating);
                    db.SaveChanges();
                    switch (rating)
                    {
                    case 0:
                        return("disliked");

                    case 100:
                        return("liked");
                    }
                }
                if (findExistingLike.Rating1 != rating)
                {
                    findExistingLike.Rating1 = rating;
                    db.SaveChanges();
                    switch (rating)
                    {
                    case 0:
                        return("disliked");

                    case 100:
                        return("liked");
                    }
                }
                return("failed");
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: GCarrell/MusicManager
 public void DeleteTab()
 {
     using (var db = new MusicManagerContext())
     {
         var listOfAssosciatedLikes = db.Ratings.Where(c => c.TabId == CurrentTab.TabId);
         db.Ratings.RemoveRange(listOfAssosciatedLikes);
         var listOfAssosciatedFavourites = db.Favourites.Where(c => c.TabId == CurrentTab.TabId);
         db.Favourites.RemoveRange(listOfAssosciatedFavourites);
         var theTab = db.Tabs.Where(c => c.TabId == CurrentTab.TabId && c.TabCreator == User.UserId);
         db.Tabs.RemoveRange(theTab);
         db.SaveChanges();
     }
 }
コード例 #5
0
ファイル: CRUDTESTS.cs プロジェクト: GCarrell/MusicManager
 public void TearDown()
 {
     using (var db = new MusicManagerContext())
     {
         var selectedUsers =
             from c in db.Users
             where c.UserName == "Padge"
             select c;
         var selectedTabs =
             from t in db.Tabs
             where t.TabName == "Through The Looking Glass"
             select t;
         db.Users.RemoveRange(selectedUsers);
         db.Tabs.RemoveRange(selectedTabs);
         db.SaveChanges();
     }
 }
コード例 #6
0
ファイル: Program.cs プロジェクト: GCarrell/MusicManager
        public (string, string) AddTabToFavourites()
        {
            using (var db = new MusicManagerContext())
            {
                var findFavourite = db.Favourites.Where(c => c.UserId == User.UserId && c.TabId == CurrentTab.TabId);
                if (findFavourite.Count() < 1)
                {
                    var newFavourite = new Favourite
                    {
                        TabId  = CurrentTab.TabId,
                        UserId = User.UserId
                    };
                    db.Favourites.Add(newFavourite);
                    db.SaveChanges();
                    return("Tab added to favourites", "pass");
                }

                return("You have already added this tab to your favourites.", "fail");
            }
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: GCarrell/MusicManager
        public (string returnMessage, string passOrFail) AddTab(string tabName, string bandName, string instrument, string tabUrl, User uploader)
        {
            using (var db = new MusicManagerContext())
            {
                var validationResult = inputValidation(tabName, bandName, instrument, tabUrl, uploader);
                if (validationResult.passOrFail == "fail")
                {
                    return(validationResult);
                }

                var newTab = new Tab
                {
                    TabName    = tabName,
                    BandName   = bandName,
                    Instrument = instrument,
                    TabUrl     = tabUrl,
                    TabCreator = uploader.UserId
                };
                db.Tabs.Add(newTab);
                db.SaveChanges();
                return("Tab uploaded Successfully", "Pass");
            }
        }