コード例 #1
0
        public static int CreateTestUser(string username, string password)
        {
            SystemUser User = new SystemUser();

            User.Username = username;
            User.Password = password;

            var dbContext = new PopcornDataEntities();

            if (dbContext.SystemUsers.Any(u => u.Username == username && u.Password == password))
            {
                int ExUserId = dbContext.SystemUsers.FirstOrDefault(u => u.Username == username && u.Password == password).Id;
                dbContext.Dispose();
                return(ExUserId);
            }

            dbContext.SystemUsers.Add(User);
            dbContext.SaveChanges();

            int UserId = dbContext.SystemUsers.FirstOrDefault(u => u.Username == username).Id;

            dbContext.Dispose();

            return(UserId);
        }
コード例 #2
0
        public static int GetPopcornNumber(int nummber)
        {
            var db = new PopcornDataEntities();
            int Id = db.Popcorns.OrderBy(p => p.Id).Skip(nummber - 1).Take(1).FirstOrDefault().Id;

            db.Dispose();
            return(Id);
        }
コード例 #3
0
        public static void DeleteTestUser(string username)
        {
            var dbContext = new PopcornDataEntities();

            dbContext.SystemUsers.RemoveRange(dbContext.SystemUsers.Where(u => u.Username == username));
            dbContext.SaveChanges();
            dbContext.Dispose();
        }