Inheritance: NerdDinner.Models.IDinnerRepository
 public ActionResult Index(int dinnerCount = 100)
 {
     const string name = "Nerd";
     var membershipService = new AccountMembershipService();
     if(membershipService.ValidateUser(name, "password") == false) {
         membershipService.CreateUser(name, "password", "*****@*****.**");
     }
     var repo = new DinnerRepository();
     foreach(var d in repo.All) {
         repo.Delete(d.DinnerID);
     }
     for (var i = 0; i < dinnerCount; i++) {
         var dinner = new Dinner {Title = "Nerd-Out",
                                  Description = "Nerding out with the nerds",
                                  EventDate = DateTime.Now.Add(new TimeSpan(30, 0, 0, 0)),
                                  ContactPhone = "403-999-9999",
                                  Address = "Calgary, AB",
                                  Country = "Canada",
                                  HostedById = name,
                                  HostedBy = name};
         var rsvp = new RSVP {AttendeeNameId = name, AttendeeName = name};
         dinner.RSVPs = new List<RSVP> {rsvp};
         repo.InsertOrUpdate(dinner);
     }
     try {
         repo.Save();
     }
     catch(DbEntityValidationException e) {
         var error = e.EntityValidationErrors.First().ValidationErrors.First();
         return new ContentResult {Content = string.Format("{0}: {1}", error.PropertyName, error.ErrorMessage)};
     }
     return new ContentResult{Content = "Success"};
 }
        protected override IEnumerable<SearchSuggestion> GetSuggestions(string term)
        {
            var dinners = new DinnerRepository().FindDinnersByText(term).ToArray();

            return from dinner in dinners
                   select new
                       SearchSuggestion
                   {
                       Description = dinner.Description,
                       Term = dinner.Title + " with " + dinner.HostedBy,
                   };
        }
        protected override IEnumerable<SearchResult> GetResults(string q)
        {
            var dinners = new DinnerRepository().FindDinnersByText(q).ToArray();

            return from dinner in dinners
                   select new
                       SearchResult
                       {
                           Description = dinner.Description,
                           Title = dinner.Title + " with " + dinner.HostedBy,
                           Path = "/" + dinner.DinnerID
                       };
        }
Beispiel #4
0
        public void ValidationTest()
        {
            var dinnerRepository = new DinnerRepository();
            var dinner = dinnerRepository.GetDinner(5);

            dinner.Country = "USA";
            dinner.ContactPhone = "425-555-BOGUS";

            if (!dinner.IsValid)
            {

                var errors = dinner.GetRuleViolations();

                Assert.AreEqual(1,errors.Count());
                dinnerRepository.Save();
            }
        }
        public ActionResult RsvpFinish()
        {
            IAuthenticationResponse response = relyingParty.GetResponse();
            if (response == null)
            {
                return RedirectToAction("Index");
            }

            if (response.Status == AuthenticationStatus.Authenticated)
            {
                var dinnerRepository = new DinnerRepository();
                string id = response.GetUntrustedCallbackArgument("DinnerId");
                Dinner dinner = dinnerRepository.GetDinner(id);

                // The alias we're getting here is NOT a secure identifier, but a friendly one,
                // which is all we need for this scenario.
                string alias = response.FriendlyIdentifierForDisplay;
                var sreg = response.GetExtension<ClaimsResponse>();
                if (sreg != null && sreg.MailAddress != null)
                {
                    alias = sreg.MailAddress.User;
                }

                // NOTE: The alias we've generated for this user isn't guaranteed to be unique.
                // Need to trim to 30 characters because that's the max for Attendee names.
                if (!dinner.IsUserRegistered(alias))
                {
                    RSVP rsvp = new RSVP();
                    rsvp.AttendeeName = alias;
                    rsvp.AttendeeNameId = response.ClaimedIdentifier;

                    dinner.RSVPs.Add(rsvp);
                    dinnerRepository.Save();
                }
            }

            return RedirectToAction("Details", "Dinners", new { id = response.GetUntrustedCallbackArgument("DinnerId") });
        }
        // GET: /RSVP/RsvpTwitterFinish
        public ActionResult RsvpTwitterFinish(string id)
        {
            string screenName;
            int userId;
            if (TwitterConsumer.TryFinishSignInWithTwitter(out screenName, out userId))
            {
                var dinnerRepository = new DinnerRepository();
                Dinner dinner = dinnerRepository.GetDinner(id);

                // NOTE: The alias we've generated for this user isn't guaranteed to be unique.
                string alias = "@" + screenName;
                if (!dinner.IsUserRegistered(alias))
                {
                    RSVP rsvp = new RSVP();
                    rsvp.DinnerID = dinner.DinnerID;
                    rsvp.AttendeeName = alias;

                    dinner.RSVPs.Add(rsvp);
                    dinnerRepository.Save();
                }
            }

            return RedirectToAction("Details", "Dinners", new { id = id });
        }