public static string Run(ModelType modelType, OperationType operationType, params object[] args)
        {
            //Reloads the context, to not get errors from entity tracking
            context = new GolfContext();

            if (operationType == OperationType.FindTotal)
            {
                return(FindTotal(int.Parse(args[0].ToString())));
            }
            else if (operationType == OperationType.FindAverage)
            {
                return(FindAverage());
            }



            if (modelType == ModelType.Course)
            {
                return(ManageCourses(operationType, args));
            }
            if (modelType == ModelType.Hole)
            {
                return(ManageHoles(operationType, args));
            }
            if (modelType == ModelType.Player)
            {
                return(ManagePlayers(operationType, args));
            }
            return("");
        }
Example #2
0
        //If want add an Admin automatically can use this.
        private void createRolesandUsers()
        {
            GolfContext context = new GolfContext();

            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));


            //In Startup I am creating first Admin Role and creating a default Admin User
            if (!roleManager.RoleExists("admin"))
            {
                //first we create Admin rool
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "admin";
                roleManager.Create(role);

                //Here we create a Admin super user who will maintain the website

                var user = new ApplicationUser();
                user.UserName = "******"; // Username has to match email
                user.Email    = "*****@*****.**";
                string userPWD = "TestTallaght55!";

                var chkUser = UserManager.Create(user, userPWD);

                //Add default User to Role Admin
                if (chkUser.Succeeded)
                {
                    var result1 = UserManager.AddToRole(user.Id, "admin");
                }
            }
        }
 static DBManager()
 {
     context          = new GolfContext();
     courseRepository = new CourseRepository(context);
     holeRepository   = new HoleRepository(context);
     playerRepository = new PlayerRepository(context);
     finder           = new DBFinder(context);
 }
Example #4
0
        public static int CalculateThru(long teamId)
        {
            var db = new GolfContext();
            var scores = db.Scores.Where(s => s.TeamID == teamId).ToList();

            if (!scores.Any()) return 0;

            var lastScore = scores.OrderByDescending(x => x.Hole.HoleNumber).FirstOrDefault();
            return lastScore?.Hole.HoleNumber ?? 0;
        }
        public void GetMembersByIdTest()
        {
            using (IDataContextAsync context = new GolfContext())
                using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
                {
                    IRepositoryAsync <Member> memberRepository = new Repository <Member>(context, unitOfWork);

                    var member = memberRepository.GetMemberById(122);
                    TestContext.WriteLine("Members found: {0}", member.Lastname);
                    Assert.AreEqual("Dustin Johnson", string.Format("{0} {1}", member.Firstname, member.Lastname));
                }
        }
        public void GetMemberByNameTest()
        {
            using (IDataContextAsync context = new GolfContext())
                using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
                {
                    IRepositoryAsync <Member> memberRepository = new Repository <Member>(context, unitOfWork);

                    var member = memberRepository.GetMemberByName("Woods", "Tiger");

                    Assert.AreEqual(1, member.MemberId);
                }
        }
Example #7
0
        public void RepositoryGetMemberByNameTest()
        {
            using (IDataContextAsync context = new GolfContext())
                using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
                {
                    IRepositoryAsync <Member> memberRepository = new Repository <Member>(context, unitOfWork);
                    IMemberService            memberService    = new MemberService(memberRepository);
                    var memberByName = memberService.GetMemberByName("Aledort", "Andy");

                    Assert.AreEqual(1, memberByName.MemberId);
                }
        }
Example #8
0
 public void FindMemberByIdTest()
 {
     using (IDataContextAsync context = new GolfContext())
         using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
         {
             IRepositoryAsync <Member> memberRepository = new Repository <Member>(context, unitOfWork);
             IService <Member>         memberService    = new MemberService(memberRepository);
             var member = memberService.Find(5);
             TestContext.WriteLine("Member found: {0}", member.Lastname);
             Assert.AreEqual("Dave Kilminster", string.Format("{0} {1}", member.Firstname, member.Lastname));
         }
 }
Example #9
0
        public void RepositoryGetMemberByIdTest()
        {
            using (IDataContextAsync context = new GolfContext())
                using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
                {
                    IRepositoryAsync <Member> memberRepository = new Repository <Member>(context, unitOfWork);
                    IMemberService            memberService    = new MemberService(memberRepository);
                    var memberById = memberService.GetMemberById(4);

                    Assert.AreEqual("James Humphries", string.Format("{0} {1}", memberById.Firstname, memberById.Lastname));
                }
        }
Example #10
0
        public void RepositoryGetAllMembersTest()
        {
            using (IDataContextAsync context = new GolfContext())
                using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
                {
                    IRepositoryAsync <Member> memberRepository = new Repository <Member>(context, unitOfWork);
                    IMemberService            memberService    = new MemberService(memberRepository);
                    var members = memberService.GetAllMembers();

                    TestContext.WriteLine("Members found: {0}", members.Count());
                    Assert.AreEqual(59, members.Count());
                }
        }
        public void GetAllMembersTest()
        {
            using (IDataContextAsync context = new GolfContext())
                using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
                {
                    IRepositoryAsync <Member> memberRepository = new Repository <Member>(context, unitOfWork);

                    var members    = memberRepository.GetAllMembers();
                    var enumerable = members as IList <Member> ?? members.ToList();
                    TestContext.WriteLine("Members found: {0}", enumerable.Count());
                    Assert.AreEqual(59, enumerable.Count());
                }
        }
        public ActionResult Index(HttpPostedFileBase CSVName)
        {
            string path = null;
            var    ProductsToDisplay = new List <Product>();

            try
            {
                if (CSVName.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(CSVName.FileName);
                    path = AppDomain.CurrentDomain.BaseDirectory + "upload\\" + fileName;
                    CSVName.SaveAs(path);

                    var csv   = new CsvReader(new StreamReader(path));
                    var db    = new GolfContext();
                    int count = 0;
                    while (csv.Read())
                    {
                        Product product = new Product();
                        product.Name          = csv.GetField <string>(0);
                        product.ProductID     = int.Parse(csv.GetField <string>(1));
                        product.Price         = decimal.Parse(csv.GetField <string>(2));
                        product.Quantity      = int.Parse(csv.GetField <string>(3));
                        product.SubDepartment = csv.GetField <string>(7);
                        product.ItemCategory  = csv.GetField <string>(8);
                        ProductsToDisplay.Add(product);
                        var exists = db.Products.Where(i => i.ProductID == product.ProductID).SingleOrDefault();
                        if (exists == null)
                        {
                            db.Products.Add(product);
                            db.SaveChanges();
                            count += 1;
                        }
                    }
                    ViewBag.RecordsUploaded = ProductsToDisplay.Count();
                    ViewBag.RecordsSaved    = count;
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
            }

            return(View(ProductsToDisplay));
        }
Example #13
0
        public static int CalculateScore(long teamId)
        {
            var score = 0;
            var par = 0;
            var db = new GolfContext();

            var currentScores = db.Scores.Where(s => s.TeamID.Equals(teamId)).ToList();

            // tally up both the total score for the team, and also the pars for the holes they've completed
            for (var i = 0; i < currentScores.Count(); i++)
            {
                score += currentScores[i].Strokes;
                var holeId = currentScores[i].HoleID;
                var thisHole = db.Holes.FirstOrDefault(h => h.HoleID == holeId);
                if (thisHole != null)
                {
                    par += thisHole.Par;
                }
            }

            return score - par;
        }
 public DBFinder(GolfContext context)
 {
     this.context = context;
 }
Example #15
0
 public HomeController()
 {
     Context = new GolfContext();
     UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(Context));
 }
Example #16
0
 public AccountController()
 {
     Context = new GolfContext();
 }
 public ScoreboardController()
 {
     Context = new GolfContext();
 }
 public ReservationService(GolfContext context)
 {
     _context = context;
 }
Example #19
0
 public RegisterViewModel()
 {
     var db = new GolfContext();
     TeamList = db.Teams.ToList();
 }
Example #20
0
 public CourseRepository(GolfContext context)
 {
     this.context = context;
     courses      = context.Courses;
 }
 public ScoresController(GolfContext context)
 {
     _context = context;
 }
Example #22
0
 public HoleRepository(GolfContext context)
 {
     this.context = context;
     holes        = context.Holes;
 }
Example #23
0
 public PlayerRepository(GolfContext context)
 {
     this.context = context;
     players      = context.Players;
 }