public ActionResult Create(Dinner dinner) { if (ModelState.IsValid) { _nerdDinners.Dinners.Add(dinner); _nerdDinners.SaveChanges(); return(RedirectToAction("Index")); } return(View()); }
private void RegisterForDinner(int id) { Dinner dinner = db.Dinners.Find(id); if (!dinner.IsUserRegistered(User.Identity.Name)) { RSVP rsvp = new RSVP(); rsvp.AttendeeName = User.Identity.Name; dinner.RSVPs.Add(rsvp); db.SaveChanges(); } }
public ActionResult Edit(Dinner dinner) { if (!dinner.IsHostedBy(User.Identity.Name)) { return(View("InvalidOwner")); } if (ModelState.IsValid) { db.Entry(dinner).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(dinner)); }
private static void SaveDinner(object sender, MsgHandlerEventArgs e) { try { Console.WriteLine($"Received message, subject: {e.Message.Subject}"); var eventMessage = MessageHelper.FromData <DinnerCreatedEvent>(e.Message.Data); Console.WriteLine($"Saving new dinner, created at: {eventMessage.CreatedAt}; event ID: {eventMessage.CorrelationId}"); var dinner = Mapper.Map <models.Dinner>(eventMessage.Dinner); using (var db = new NerdDinnerContext()) { dinner.RSVPs = new List <RSVP> { new RSVP { AttendeeName = dinner.HostedBy } }; db.Dinners.Add(dinner); db.SaveChanges(); } Console.WriteLine($"Dinner saved. Dinner ID: {dinner.DinnerID}; event ID: {eventMessage.CorrelationId}"); } catch (Exception ex) { Console.WriteLine($"Exception processing event: {ex}"); } }
/// <summary> /// Adds the specified user names to the specified roles for the configured applicationName. /// </summary> /// <param name="usernames">A string array of user names to be added to the specified roles. </param><param name="roleNames">A string array of the role names to add the specified user names to.</param> public override void AddUsersToRoles(string[] usernames, string[] roleNames) { //create a new BrightstarDB context using the values in Web.config var context = new NerdDinnerContext(); foreach (var username in usernames) { //find the match for the username var login = context.NerdDinnerLogins.Where(l => l.Username.Equals(username)).FirstOrDefault(); if (login == null) { continue; } foreach (var role in roleNames) { //if the Roles collection of the login does not already contain the role, then add it if (login.Roles.Contains(role)) { continue; } login.Roles.Add(role); } } context.SaveChanges(); }
public ActionResult Create(Dinner dinner) { if (ModelState.IsValid) { dinner.HostedBy = User.Identity.Name; RSVP rsvp = new RSVP(); rsvp.AttendeeName = User.Identity.Name; dinner.RSVPs = new List <RSVP>(); dinner.RSVPs.Add(rsvp); db.Dinners.Add(dinner); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(dinner)); }
// GET: Rsvp/Create public IActionResult Create(long id) { Rsvp rsvp = new Rsvp { DinnerId = id, UserName = _userManager.GetUserName(User) }; _context.Add(rsvp); _context.SaveChanges(); return(View(rsvp)); }
public override MembershipUser GetUser(string username, bool userIsOnline) { if (string.IsNullOrEmpty(username)) { return(null); } //Create a context using the connection string in Web.config var context = new NerdDinnerContext(); //Query the store for a NerdDinnerLogin that matches the supplied username var login = context.NerdDinnerLogins.Where(l => l.Username.Equals(username)).FirstOrDefault(); if (login == null) { return(null); } if (userIsOnline) { //if the call states that the user is online, update the LastActive property of the NerdDinnerLogin login.LastActive = DateTime.UtcNow; context.SaveChanges(); } return(ConvertLoginToMembershipUser(login)); }
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { var args = new ValidatePasswordEventArgs(email, password, true); OnValidatingPassword(args); if (args.Cancel) { status = MembershipCreateStatus.InvalidPassword; return(null); } if (string.IsNullOrEmpty(email)) { status = MembershipCreateStatus.InvalidEmail; return(null); } if (string.IsNullOrEmpty(password)) { status = MembershipCreateStatus.InvalidPassword; return(null); } if (RequiresUniqueEmail && GetUserNameByEmail(email) != "") { status = MembershipCreateStatus.DuplicateEmail; return(null); } var u = GetUser(username, false); try { if (u == null) { var salt = CreateSalt(); //Create a new NerdDinnerLogin entity and set the properties var login = new NerdDinnerLogin { Username = username, Email = email, PasswordSalt = salt, Password = CreatePasswordHash(password, salt), CreatedDate = DateTime.UtcNow, IsActivated = true, IsLockedOut = false, LastLockedOutDate = DateTime.UtcNow, LastLoginDate = DateTime.UtcNow, LastActive = DateTime.UtcNow }; //Create a context using the connection string in the Web.Config var context = new NerdDinnerContext(); //Add the entity to the context context.NerdDinnerLogins.Add(login); //Save the changes to the BrightstarDB store context.SaveChanges(); status = MembershipCreateStatus.Success; return(GetUser(username, true /*online*/)); } } catch (Exception) { status = MembershipCreateStatus.ProviderError; return(null); } status = MembershipCreateStatus.DuplicateUserName; return(null); }