コード例 #1
0
ファイル: Program.cs プロジェクト: ShaheedKara/ProjectBET
        static void Main(string[] args)
        {
            var Basket = new Basket();

            var Shirt = new Shirt(); //Adding test data

            Shirt.Name = "Armani";
            Shirt.Size = "l";
            Basket.shirts.Add(Shirt);
            var Golf = new Golfer();

            Golf.Name = "White";
            Golf.Size = "m";
            Basket.golfers.Add(Golf);
            var jean = new Jeans();

            jean.Name = "Skinny";
            jean.Size = "s";
            Basket.jeans.Add(jean);
            var formal = new Formal();

            formal.Name = "Guess";
            formal.Size = "l";
            Basket.formals.Add(formal);


            Console.WriteLine("Your total is : R" + Basket.CalcCost()); //output
            Console.ReadKey();
        }
コード例 #2
0
        public async Task CanCreateGolfer()
        {
            var client    = factory.CreateClient();
            var emptyForm = await client.GetAsync(new Uri("/Admin/Golfers/Edit", UriKind.Relative));

            var formDocument = await emptyForm.GetDocumentAsync();

            var golfer = new Golfer()
            {
                FirstName      = "Annie",
                LastName       = "Oaks",
                EmailAddress   = "*****@*****.**",
                PhoneNumber    = "301-555-1212",
                LeagueHandicap = 12,
                Tee            = TeeType.Red,
                IsActive       = true
            };

            var formPost = await client.SendFormAsync(formDocument, "Golfer", golfer);

            var postDocument = await formPost.GetDocumentAsync();

            using var scope = factory.Services.GetScopedDbContext <LeagueDbContext>();
            Assert.Single(scope.Db.Golfers);
        }
コード例 #3
0
        /// <summary>
        /// Changes the password of a given user.
        /// </summary>
        /// <param name="username">The ussername of the user to change password on.</param>
        /// <param name="oldPassword">The users old password.</param>
        /// <param name="newPassword">The users new password.</param>
        /// <returns>Returns true if the user was found, their old password matched and the new password was set.  Returns false otherwise.</returns>
        public override bool ChangePassword(string username, string oldPassword, string newPassword)
        {
            if ((username == null || username.Length == 0) || (oldPassword == null || oldPassword.Length == 0) || (newPassword == null || newPassword.Length == 0))
            {
                throw new ArgumentException("A username, old password and new password are required.");
            }

            int?golferId = _golferRetriever.GetGolferIdByWebLogin(username, oldPassword);

            if (golferId == null)
            {
                return(false);
            }

            Golfer golfer = _golferRetriever.LoadByGolferId((int)golferId);

            string salt           = PasswordCrypto.GetSalt();
            string hashedPassword = PasswordCrypto.ComputeHash(newPassword, "SHA256", salt);

            golfer.PasswordHash = hashedPassword;
            golfer.PasswordSalt = salt;

            //TODO:  fix
            return(true);
        }
コード例 #4
0
 /// <summary>
 /// Validates the specified user.
 /// </summary>
 /// <param name="user"></param>
 private static void ValidateUser(Golfer golfer)
 {
     if (golfer == null)
     {
         throw new ArgumentNullException("No session user specified.");
     }
 }
コード例 #5
0
        public void CanCreateMatchSetResult()
        {
            var season = new Season()
            {
                Name = seasonName, Id = 310
            };
            var week = new MatchSet()
            {
                Date = matchSetDate
            };
            var matchSet = season.AddWeek(week);

            var golfer1 = new Golfer()
            {
                Id             = 1,
                LeagueHandicap = 10
            };

            var golfer2 = new Golfer
            {
                Id             = 2,
                LeagueHandicap = 7
            };

            var match = matchSet.AddResult(golfer1, 3, 3.5m, true, golfer2, 2, 7.5m, false);

            Assert.Equal(1, matchSet.Matches.Count);
            Assert.Equal(11, matchSet.Matches.First().Players.Sum(p => p.Points));
        }
コード例 #6
0
        static void Main(string[] args)
        {
            var basket = new Basket();

            var tshirt = new TShirt();

            tshirt.Name = "DC Comics";
            tshirt.Size = "m";
            basket.Shirts.Add(tshirt);

            var golfer = new Golfer();

            golfer.Name = "Golfer";
            golfer.Size = "m";
            basket.Shirts.Add(golfer);

            var formalPants = new FormalPants();

            formalPants.Name = "Formal Pants";
            formalPants.Size = "m";
            basket.PantsList.Add(formalPants);

            var jeans = new Jeans();

            jeans.Name = "Jeans";
            jeans.Size = "m";
            basket.PantsList.Add(jeans);

            Console.WriteLine($"Your total price is {basket.GetTotalPrice()}");
            Console.Read();
        }
コード例 #7
0
        // GET: HoleScores/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HoleScore holeScore = db.HoleScores.Find(id);

            if (holeScore == null)
            {
                return(HttpNotFound());
            }
            GolfCourse golfCourse = db.Courses.Find(holeScore.GolfCourseID);

            if (golfCourse == null)
            {
                return(HttpNotFound());
            }
            Golfer golfer = db.Golfers.Find(holeScore.GolferID);

            if (golfer == null)
            {
                return(HttpNotFound());
            }
            ViewBag.GolfCourseName = golfCourse.Name;
            ViewBag.GolferName     = golfer.FirstName + " " + golfer.LastName;
            return(View(holeScore));
        }
コード例 #8
0
        public IHttpActionResult PutGolfer(int id, Golfer golfer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != golfer.ID)
            {
                return(BadRequest("Golfer with ID doesn't exist"));
            }

            // commented line for unit tests and added the mark as modified, reverse before deploying
            db.Entry(golfer).State = EntityState.Modified;
            //db.MarkAsModified(golfer);
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GolferExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #9
0
        static async Task GetsGolfersAsync()
        {
            // GET: api/Golfer/all
            HttpResponseMessage response = await golfResultsAPI.GetAsync("api/Golfer/all");

            if (response.IsSuccessStatusCode)
            {
                var returnedGolfers = await response.Content.ReadAsAsync <IEnumerable <Golfer> >(); // add from Console line

                Console.WriteLine("\n*** Complete Golfer List ***");
                foreach (Golfer g in returnedGolfers)
                {
                    Console.WriteLine(g);
                }
            }

            // GET: api/Golfer/GetGolfer/1
            response = await golfResultsAPI.GetAsync("api/Golfer/GetGolfer/1");

            if (response.IsSuccessStatusCode)
            {
                var returnedGolfer = await response.Content.ReadAsAsync <Golfer>(); // add from Console line

                Console.WriteLine("\n*** Golfer with ID of 1 is ***" + returnedGolfer);
            }


            // POST: api/Golfer/PostGolfer
            Golfer g1 = new Golfer()
            {
                Firstname = "Sergio", Surname = "Garcia"
            };

            response = golfResultsAPI.PostAsJsonAsync("api/Golfer/PostGolfer", g1).Result;
            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine("\nAdded Golfer: " + g1.FullName);
            }


            // PUT: api/Golfer/PutGolfer/2
            Golfer g2 = new Golfer()
            {
                ID = 2, Firstname = "Sergio", Surname = "Garcia"
            };

            response = golfResultsAPI.PutAsJsonAsync("api/Golfer/PutGolfer/2", g2).Result;
            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine("\nUpdated Golfer: " + g2.FullName);
            }


            // DELETE: api/Golfer/DeleteGolfer/2
            response = golfResultsAPI.DeleteAsync("api/Golfer/DeleteGolfer/6").Result;
            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine("\nDeleted Golfer: " + response.IsSuccessStatusCode);
            }
        }
コード例 #10
0
ファイル: GolferService.cs プロジェクト: rer145/fantasy-golf
        public static void Save(string firstName, string lastName, int tourId)
        {
            //TODO: need to handle spelling updates by passing in ID #

            using (var db = new FantasyGolfContext())
            {
                var query = from x in db.Golfer
                            where x.FirstName == firstName && x.LastName == lastName && x.TourId == tourId
                            select x;

                var golfer = query.FirstOrDefault();

                if (golfer == null)
                {
                    golfer = new Golfer();
                    db.Golfer.Add(golfer);
                }
                else
                {
                    db.Entry(golfer).State = System.Data.Entity.EntityState.Modified;
                }

                golfer.FirstName    = firstName;
                golfer.LastName     = lastName;
                golfer.TourId       = tourId;
                golfer.CreatedOn    = DateTime.Now;
                golfer.LastSyncedOn = null;
                golfer.IsActive     = true;

                db.SaveChanges();

                var cache = new CacheService();
                cache.Remove("fg.golfers");
            }
        }
コード例 #11
0
        static void Main(string[] args)
        {
            var basket = new Basket();
            var shirt  = new TShirt();

            shirt.Name = "Dc Shirt";
            shirt.Size = "m";
            basket.shirts.Add(shirt);

            var golfer = new Golfer();

            golfer.Name = "Old Khaki Golfer";
            golfer.Size = "l";
            basket.shirts.Add(golfer);

            var jeans = new Jeans();

            jeans.Name = "Levis Jeans";
            jeans.Size = "s";
            basket.pants.Add(jeans);

            var formalpants = new FormalPants();

            formalpants.Name = "Formal Pants";
            formalpants.Size = "m";
            basket.pants.Add(formalpants);


            Console.WriteLine($"Your total price is {basket.GetTotalPrice()}");
            Console.ReadKey();
        }
コード例 #12
0
 public ActionResult Create([Bind(Include = "Surname, Firstname")] Golfer golfer)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var foundName = db.Golfers.FirstOrDefault(i => i.Firstname == golfer.Firstname && i.Surname == golfer.Surname);
             if (foundName != null)
             {
                 ModelState.AddModelError(string.Empty, "Golfer already exists.");
             }
             else
             {
                 db.Golfers.Add(golfer);
                 db.SaveChanges();
                 return(RedirectToAction("Index"));
             }
         }
     }
     catch (DataException /* dex */)
     {
         //Log the error (uncomment dex variable name and add a line here to write a log.
         ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
     }
     return(View(golfer));
 }
コード例 #13
0
        public async Task <IHttpActionResult> Put(string id, [FromBody] Golfer entity)
        {
            await _repo.UpdateDocumentAsync(entity);

            var model = _repo.GetById(id);

            return(Ok(model));
        }
コード例 #14
0
        public void CanFailPassword()
        {
            var hasher = new PasswordManager();
            var golfer = new Golfer();

            hasher.SetPassword(golfer, "123abc!@#");
            Assert.False(hasher.VerifyPassword(golfer, "1"));
        }
コード例 #15
0
        public ActionResult DeleteConfirmed(int id)
        {
            Golfer golfer = db.Golfers.Find(id);

            db.Golfers.Remove(golfer);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #16
0
ファイル: CBS.cs プロジェクト: ChaseDDevelopment/ClubBAIST
        public bool ReviewMembershipApplication(Golfer golfer)
        {
            bool    Confirmation = false;
            Golfers dataManager  = new Golfers();

            Confirmation = dataManager.ReviewMembershipApplication(golfer);
            return(Confirmation);
        }
コード例 #17
0
        public async Task <IHttpActionResult> Post([FromBody] Golfer entity)
        {
            var result = await _repo.CreateDocumentAsync(entity);

            var id    = result.Resource.Id;
            var model = _repo.GetById(id);

            return(Ok(model));
        }
コード例 #18
0
        public void CanSetAndVerifyPassword()
        {
            var hasher = new PasswordManager();
            var golfer = new Golfer();

            hasher.SetPassword(golfer, "123abc!@#");
            Assert.True(!string.IsNullOrEmpty(golfer.PasswordHash));
            Assert.True(hasher.VerifyPassword(golfer, "123abc!@#"));
        }
コード例 #19
0
 /// <summary>
 /// Sets the <see cref="BusinessContactView">user</see> for the current session.
 /// </summary>
 /// <param name="businessContactId"></param>
 internal void SetSessionUser(int golferId)
 {
     Clear();
     _golfer = golferRetriever.LoadByGolferId(golferId);
     if (_golfer == null)
     {
         throw new ArgumentException("No such golfer found.");
     }
 }
コード例 #20
0
 public ActionResult Edit([Bind(Include = "GolferID,LastName,FirstName,GhinNum")] Golfer golfer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(golfer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(golfer));
 }
コード例 #21
0
 public ActionResult Edit([Bind(Include = "intPersonID,strFirstName,strLastName,strNickname")] Golfer golfer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(golfer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(golfer));
 }
コード例 #22
0
        public ActionResult Create([Bind(Include = "GolferID,LastName,FirstName,GhinNum")] Golfer golfer)
        {
            if (ModelState.IsValid)
            {
                db.Golfers.Add(golfer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(golfer));
        }
コード例 #23
0
        public IHttpActionResult GetGolfer(int id)
        {
            Golfer golfer = db.Golfers.Find(id);

            if (golfer == null)
            {
                return(NotFound());
            }

            return(Ok(golfer));
        }
コード例 #24
0
        public ActionResult Create([Bind(Include = "intPersonID,strFirstName,strLastName,strNickname")] Golfer golfer)
        {
            if (ModelState.IsValid)
            {
                db.Golfers.Add(golfer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(golfer));
        }
コード例 #25
0
    protected void EditButtonClick(object sender, CommandEventArgs e)
    {
        int    golferID   = int.Parse((string)e.CommandArgument);
        Golfer golferInfo = DatabaseFunctions.GetGolferInfo(golferID);

        TextBoxFirstName.Text    = golferInfo.firstName;
        TextBoxLastName.Text     = golferInfo.lastName;
        TextBoxEmailAddress.Text = golferInfo.emailAddress;
        TextBoxNickName.Text     = golferInfo.nickName;
        btnSave.CommandArgument  = golferID.ToString();
        ModalPopupExtender1.Show();
    }
コード例 #26
0
        // POST: api/GolfClub/AddMember
        public IHttpActionResult AddMember(Golfer newGolfer)
        {
            var foundgolfer = GolfersList.FirstOrDefault(p => p.GUI == newGolfer.GUI);

            if (foundgolfer != null)
            {
                return(BadRequest("Sorry a Golfer with this GUI already exists"));
            }
            else
            {
                GolfersList.Add(newGolfer);
                return(Ok());
            }
        }
コード例 #27
0
        public IHttpActionResult DeleteGolfer(int id)
        {
            Golfer golfer = db.Golfers.Find(id);

            if (golfer == null)
            {
                return(NotFound());
            }

            db.Golfers.Remove(golfer);
            db.SaveChanges();

            return(Ok(golfer));
        }
コード例 #28
0
        // GET: Golfers/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Golfer golfer = db.Golfers.Find(id);

            if (golfer == null)
            {
                return(HttpNotFound());
            }
            return(View(golfer));
        }
コード例 #29
0
        public bool VerifyPassword(Golfer golfer, string password)
        {
            var result = _hasher.VerifyHashedPassword(golfer, golfer.PasswordHash, password);

            if (result == PasswordVerificationResult.SuccessRehashNeeded)
            {
                throw new Exception("Password rehash needed");
            }
            if (result == PasswordVerificationResult.Success)
            {
                return(true);
            }
            return(false);
        }
コード例 #30
0
        private IEnumerable <Claim> GetUserClaims(Golfer golfer)
        {
            IEnumerable <Claim> claims = new Claim[]
            {
                new Claim(ClaimTypes.Name, golfer.FirstName + " " + golfer.LastName),
                new Claim(ClaimTypes.Email, golfer.Email),
                new Claim("MembershipLevel", golfer.MembershipLevel.ToString()),
                new Claim("MemberNumber", golfer.MemberNumber.ToString()),
                new Claim("Shareholder", golfer.Shareholder.ToString()),
                new Claim("Approved", golfer.Approved.ToString()),
            };

            return(claims);
        }
コード例 #31
0
    static void Main(string[] args)
    {
        Console.Out.WriteLine(new Golfer().Call("Drive", "Reflection"));
        Console.Out.WriteLine(new RaceCarDriver().Call("Drive", "Reflection"));

        dynamic caller = new Golfer();
        Console.Out.WriteLine(caller.Drive("Dynamic"));

        var rangeOne = new Range(-10d, 10d);
        var rangeTwo = new Range(-5d, 15d);
        Console.Out.WriteLine(rangeOne + rangeTwo);

        Console.ReadLine();
    }