Example #1
0
        public GolferContract UpdateGolfer(CreateGolferContract updatedGolfer)
        {
            var golferRetriever = RetrieverFactory.CreateInterface <IGolferRetriever>();
            var foundGolfer     = golferRetriever.LoadByGolferId(CurrentSession.GolferId);

            using (NeedAGolferDataContext dataContext = new NeedAGolferDataContext())
            {
                foundGolfer.AllowEmails          = updatedGolfer.AllowEmails;
                foundGolfer.AvailabilityDistance = updatedGolfer.AvailabilityDistanceInMiles;
                foundGolfer.EmailAddress         = updatedGolfer.EmailAddress;
                foundGolfer.Handicap             = updatedGolfer.Handicap;
                foundGolfer.IsAvailable          = updatedGolfer.IsAvailable;
                foundGolfer.LastUpdated          = DateTime.Now;
                foundGolfer.Latitude             = updatedGolfer.Latitude;
                foundGolfer.Longitude            = updatedGolfer.Longitude;
                foundGolfer.ScreenName           = updatedGolfer.Name;
                foundGolfer.PhoneNumber          = updatedGolfer.PhoneNumber;

                dataContext.Golfers.Attach(foundGolfer, true);
                dataContext.SubmitChanges();
                dataContext.Connection.Close();
                GolferContract contract = new GolferContract(foundGolfer);
                return(contract);
            }
        }
Example #2
0
        public VoidOperationContract CreateGolfer(CreateGolferContract createContract)
        {
            VoidOperationContract contract = new VoidOperationContract();

            try
            {
                using (NeedAGolferDataContext dataContext = new NeedAGolferDataContext())
                {
                    var existing = from golfers in dataContext.Golfers
                                   where (golfers.ScreenName == createContract.Name || golfers.EmailAddress == createContract.EmailAddress)
                                   select golfers;

                    if (existing.Count() == 0)
                    {
                        Golfer golfer = new Golfer();
                        golfer.EmailAddress         = createContract.EmailAddress;
                        golfer.AllowEmails          = false;
                        golfer.PhoneNumber          = createContract.PhoneNumber;
                        golfer.IsAvailable          = true;
                        golfer.Handicap             = createContract.Handicap;
                        golfer.Latitude             = createContract.Latitude;
                        golfer.Longitude            = createContract.Longitude;
                        golfer.LastUpdated          = DateTime.Now;
                        golfer.ScreenName           = createContract.Name;
                        golfer.AvailabilityDistance = createContract.AvailabilityDistanceInMiles;

                        string salt           = PasswordCrypto.GetSalt();
                        string hashedPassword = PasswordCrypto.ComputeHash(createContract.Password, "SHA256", salt);
                        golfer.PasswordHash = hashedPassword;
                        golfer.PasswordSalt = salt;

                        dataContext.Golfers.InsertOnSubmit(golfer);
                        dataContext.SubmitChanges();
                        dataContext.Connection.Close();
                    }
                    else
                    {
                        contract.ErrorMessage = "There is already a user registered with this screen name or email address.  Please try again.";
                    }
                }
            }
            catch (Exception ex)
            {
                contract.ErrorMessage = ex.Message;
            }
            return(contract);
        }