public static UserRegistrationKeyViewModel ToViewModel(this UserRegistrationKey key)
        {
            var vm = new UserRegistrationKeyViewModel()
            {
                UsesRemaining           = key.UsesRemaining,
                Active                  = key.Active,
                Key                     = key.Key,
                UserRegistrationKeyId   = key.UserRegistrationKeyId,
                UserRegistrationKeyUses = key.UserRegistrationKeyUses.ToViewModel()
            };

            return(vm);
        }
        public UserRegistrationKey Create(UserRegistrationKeyViewModel model)
        {
            if (null != Get(model.Key))
            {
                throw new EntityValidationException("A registration key with the given value already exists.");
            }

            var toCreate = new UserRegistrationKey()
            {
                UsesRemaining = model.UsesRemaining,
                Active        = model.Active,
                Key           = model.Key
            };

            _db.UserRegistrationKeys.Add(toCreate);
            _db.SaveChanges();

            return(Get(toCreate.UserRegistrationKeyId));
        }