Ejemplo n.º 1
0
        public ActionResult InvitationDecline(int invitationId)
        {
            Invitation invitation = db.Invitations.AsNoTracking().First(i => i.Id == invitationId);

            // Verify that the Invitation has not already been Accepted or Declined - This is a second layer of security as it was already handled in the View
            if (invitation.HasAccepted == true || invitation.HasDeclined == true)
            {
                return(RedirectToAction("NotAuthorized", "Account"));
            }

            // Mark Invitation as Declined so it does not show up in the list of Unresponded Invitations
            invitation.HasDeclined     = true;
            db.Entry(invitation).State = EntityState.Modified;
            db.SaveChanges();

            // Mark Invitation Notification as Acknowledged so it does not show up on the list of Unread/Unacknowledged Notifications
            Notification notification = db.Notifications.AsNoTracking().First(n => n.Id == invitation.NotificationId);

            notification.IsAcknowledged  = true;
            db.Entry(notification).State = EntityState.Modified;
            db.SaveChanges();

            // Create a Notification to the Household Members indicating that the Invitation was Declined
            var household = db.Households.Find(invitation.HouseholdId);
            NotificationsController notificationController = new NotificationsController();

            notificationController.CreateInvitationResponseNotification(invitation.Id, false);

            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> InvitationAccept(int invitationId)
        {
            Invitation      invitation = db.Invitations.AsNoTracking().First(i => i.Id == invitationId);
            ApplicationUser user       = db.Users.Find(User.Identity.GetUserId());

            // Verify that the Invitation has not already been Accepted or Declined - This is a second layer of security as it was already handled in the View
            if (invitation.HasAccepted == true || invitation.HasDeclined == true)
            {
                return(RedirectToAction("NotAuthorized", "Account"));
            }

            // Doublechecking that the logged in user is also the Invitee
            if (user.Email != invitation.InviteeEmail)
            {
                return(RedirectToAction("NotAuthorized", "Account"));
            }

            // If Invitee is in another HH, they have to leave that HH before joining this one.
            if (user.HouseholdId != null)
            {
                LeaveHouseholdHelper leaveHelper = new LeaveHouseholdHelper();
                leaveHelper.LeaveHousehold(user);
            }

            // Add User to the Household
            user.HouseholdId     = invitation.HouseholdId;
            user.DateJoined      = DateTime.UtcNow;
            db.Entry(user).State = EntityState.Modified;
            db.SaveChanges();

            // Mark Invitation as Accepted so it does not show up in the list of Unresponded Invitations
            invitation.HasAccepted     = true;
            db.Entry(invitation).State = EntityState.Modified;
            db.SaveChanges();

            // Mark Notification as Acknowledged so it does not show up on the list of Unread/Unacknowledged Notifications
            Notification notification = db.Notifications.AsNoTracking().First(n => n.Id == invitation.NotificationId);

            notification.IsAcknowledged  = true;
            db.Entry(notification).State = EntityState.Modified;
            db.SaveChanges();

            // Send a notification to the Members of the Household indicating that there is a new Member
            NotificationsController notificationController = new NotificationsController();

            notificationController.CreateInvitationResponseNotification(invitation.Id, true);

            await HttpContext.RefreshAuthentication(db.Users.Find(User.Identity.GetUserId()));

            return(RedirectToAction("Index", "Households"));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Create([Bind(Include = "Id,InvitationMessage,InviteeEmail")] Invitation invitation)
        {
            ApplicationUser user = db.Users.Find(User.Identity.GetUserId());

            if (ModelState.IsValid)
            {
                invitation.HasAccepted = false;
                invitation.HasDeclined = false;
                invitation.InviterId   = user.Id;
                invitation.HouseholdId = user.HouseholdId.Value;
                invitation.Created     = DateTime.UtcNow;
                db.Invitations.Add(invitation);
                db.SaveChanges();
                NotificationsController notification = new NotificationsController();
                Task <int> sendNotification          = notification.CreateInvitationNotification(invitation.Id);
                int        result = await sendNotification;
                result++;
                return(RedirectToAction("Index"));
            }

            ViewBag.InviteeId = new SelectList(db.Users.Where(u => u.Id != user.Id), "Id", "FirstName");
            return(View(invitation));
        }