예제 #1
0
        public async Task <UserCheckin> RemindAccountAsync(string userName)
        {
            var profile = await _db.Set <UserProfile>().SingleOrDefaultAsync(p => p.User.Name == userName && p.User.AccountState != BL.Enum.AccountState.Disabled);

            if (profile == null)
            {
                throw new UserAccountException("user name not found.");
            }
            foreach (var oldCheckin in _db.Set <UserCheckin>().Where(ch => ch.IsUsed == false && ch.UserProfile.Id == profile.Id))
            {
                oldCheckin.IsUsed = true;
            }
            var userCheckin = new UserCheckin
            {
                UserProfile       = profile,
                CheckinAddr       = profile.Email,
                NotifyChannelType = BL.Enum.NotifyChannelType.Email,
                UserCheckinType   = BL.Enum.UserCheckinType.ChangeAccount
            };

            userCheckin.Msg = $"Welcome! To change your account link with code: {userCheckin.Code}";
            await _db.Set <UserCheckin>().AddAsync(userCheckin);

            await _db.SaveChangesAsync();

            return(userCheckin);
        }
예제 #2
0
        public async Task MarkUserCheckinNotifiedAsync(UserCheckin userCheckin)
        {
            userCheckin = await _db.Set <UserCheckin>().FindAsync(userCheckin.Id);

            if (userCheckin != null && userCheckin.NotifyDate == null)
            {
                userCheckin.NotifyDate = DateTime.Now;
                await _db.SaveChangesAsync();
            }
        }
        public int CheckIn(Guid userId, long listingId)
        {
            var checkin = new UserCheckin {CheckedIn = DateTime.Now, ListingId = listingId, UserId = userId};

            using (var objectContext = new ybsquareEntities())
            {
                objectContext.UserCheckins.AddObject(checkin);
                objectContext.SaveChanges();
            }

            return checkin.Id;
        }
예제 #4
0
        public async Task <User> ChangeAccountAsync(UserCheckin checkin, string userName, string userPwd)
        {
            if (checkin.UserProfile.User.AccountState == BL.Enum.AccountState.Disabled)
            {
                throw new UserAccountException("Invalid account.");
            }
            if (_db.Set <User>().Any(u => u.Name == userName && u.Id != checkin.UserProfile.Id))
            {
                throw new UserAccountException("Invalid user name.");
            }
            checkin.UserProfile.User.Name = userName;
            checkin.UserProfile.User.SetPassword(userPwd);
            checkin.UserProfile.User.AccountState = BL.Enum.AccountState.Active;
            checkin.IsUsed      = true;
            checkin.CheckinDate = DateTime.Now;
            await _db.SaveChangesAsync();

            return(checkin.UserProfile.User);
        }
예제 #5
0
        public async Task <UserCheckin> RegisterAccountAsync(UserProfile profile)
        {
            if (_db.Set <User>().Any(u => u.Name == profile.User.Name))
            {
                throw new UserAccountException("Invalid user.");
            }
            profile.User.SetPassword(Guid.NewGuid().ToString());
            var userCheckin = new UserCheckin
            {
                UserProfile       = profile,
                CheckinAddr       = profile.Email,
                NotifyChannelType = BL.Enum.NotifyChannelType.Email,
                UserCheckinType   = BL.Enum.UserCheckinType.RegisterAccount
            };

            userCheckin.Msg = $"Welcome! Confirm your register with code: {userCheckin.Code}";
            await _db.Set <UserCheckin>().AddAsync(userCheckin);

            await _db.SaveChangesAsync();

            return(userCheckin);
        }