Пример #1
0
 public InvitationLog Remove(InvitationLog entity)
 {
     HttpContext.Current.Cache.Remove("InvitationLogs"); // invalidate cache
     Entry(entity).State = System.Data.EntityState.Deleted;
     return entity;
 }
Пример #2
0
 public DbEntityEntry<InvitationLog> Entry(InvitationLog entity)
 {
     HttpContext.Current.Cache.Remove("InvitationLogs"); // invalidate cache
     return db.Entry<InvitationLog>(entity);
 }
Пример #3
0
 public InvitationLog Add(InvitationLog entity)
 {
     HttpContext.Current.Cache.Remove("InvitationLogs"); // invalidate cache
     return db.InvitationLogs.Add(entity);
 }
Пример #4
0
        private void SendEmailInvitation(User user)
        {
            IUserMailer mailer = new UserMailer();
            var message = mailer.Invitation(user);
            message.Send();

            var log = new InvitationLog()
            {
                UserId = user.UserId,
                Action = (int)InvitationAction.Sent,
                LogDate = DateTime.UtcNow
            };
            repo.Add(log);
        }
Пример #5
0
        private void CreateOrUpdateDbUser(string claimedIdentifier, string email, string invitationCode)
        {
            // see if user already exists
            var ExistingUserByOpenId = repo.Users.SingleOrDefault(u => u.ClaimedIdentifier == claimedIdentifier);
            var ExistingUserByInvite = repo.Users.SingleOrDefault(u => u.InvitationCode == invitationCode);

            if (ExistingUserByOpenId != null && ExistingUserByInvite != null)
            {
                // the user that accepted the invite already had an account. Delete the invite
                repo.Remove(ExistingUserByInvite);
                ExistingUserByInvite = null;
            }

            var ExistingUser = ExistingUserByOpenId ?? ExistingUserByInvite;

            if (ExistingUser == null)
            {
                var NewUser = new User
                {
                    ClaimedIdentifier = claimedIdentifier,
                    Email = email,
                    FirstLogin = DateTime.UtcNow,
                    LastLogin = DateTime.UtcNow,
                    LoginCount = 1,
                    RoleId = (int)RoleType.Guest
                };

                repo.Add(NewUser);
            }
            else
            {
                if (ExistingUser.ClaimedIdentifier == null)
                {
                    ExistingUser.ClaimedIdentifier = claimedIdentifier;
                    ExistingUser.FirstLogin = DateTime.UtcNow;
                    ExistingUser.InvitationCode = null; // clear out code since it's been redeemed

                    var log = new InvitationLog()
                    {
                        UserId = ExistingUser.UserId,
                        Action = (int)InvitationAction.Accepted,
                        LogDate = DateTime.UtcNow
                    };
                    repo.Add(log);
                }
                ExistingUser.Email = email;
                ExistingUser.LoginCount++;
                ExistingUser.LastLogin = DateTime.UtcNow;
            }
            repo.SaveChanges();
        }
Пример #6
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                // generate a new invite code
                user.InvitationCode = Extensions.Utilities.GenerateKey();
                repo.Add(user);
                repo.SaveChanges();

                var LogEntry = new InvitationLog()
                {
                    Action = (int)InvitationAction.Created,
                    UserId = user.UserId,
                    LogDate = DateTime.UtcNow
                };

                repo.Add(LogEntry);

                try
                {
                    SendEmailInvitation(user);
                    TempData["Message"] = "Invitation Sent";
                }
                catch (Exception ex)
                {
                    TempData["Message"] = string.Format("Invitation created, but could not be sent :( ({0})", ex.Message);
                }

                repo.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.Organizations = repo.Organizations.ToSelectListItems();
            ViewBag.Servicers = repo.Servicers.ToSelectListItems();
            return View(user);
        }